forked from mirror/qmk_firmware
Add missing SVN eol-style property to files where it was missing.
This commit is contained in:
@@ -1,164 +1,164 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the HID class bootloader. This file contains the complete bootloader logic.
|
||||
*/
|
||||
|
||||
#include "BootloaderHID.h"
|
||||
|
||||
/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
|
||||
* via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application
|
||||
* started via a forced watchdog reset.
|
||||
*/
|
||||
static bool RunBootloader = true;
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* Setup hardware required for the bootloader */
|
||||
SetupHardware();
|
||||
|
||||
/* Enable global interrupts so that the USB stack can function */
|
||||
sei();
|
||||
|
||||
while (RunBootloader)
|
||||
USB_USBTask();
|
||||
|
||||
/* Disconnect from the host - USB interface will be reset later along with the AVR */
|
||||
USB_Detach();
|
||||
|
||||
/* Enable the watchdog and force a timeout to reset the AVR */
|
||||
wdt_enable(WDTO_250MS);
|
||||
|
||||
for (;;);
|
||||
}
|
||||
|
||||
/** Configures all hardware required for the bootloader. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Relocate the interrupt vector table to the bootloader section */
|
||||
MCUCR = (1 << IVCE);
|
||||
MCUCR = (1 << IVSEL);
|
||||
|
||||
/* Initialize USB subsystem */
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** 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 HID Report Endpoint */
|
||||
Endpoint_ConfigureEndpoint(HID_IN_EPNUM, EP_TYPE_INTERRUPT,
|
||||
ENDPOINT_DIR_IN, HID_IN_EPSIZE,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
}
|
||||
|
||||
/** 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 HID interface */
|
||||
if ((USB_ControlRequest.bmRequestType & (CONTROL_REQTYPE_TYPE | CONTROL_REQTYPE_RECIPIENT)) !=
|
||||
(REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Process HID specific control requests */
|
||||
switch (USB_ControlRequest.bRequest)
|
||||
{
|
||||
case HID_REQ_SetReport:
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Wait until the command has been sent by the host */
|
||||
while (!(Endpoint_IsOUTReceived()));
|
||||
|
||||
/* Read in the write destination address */
|
||||
#if (FLASHEND > 0xFFFF)
|
||||
uint32_t PageAddress = ((uint32_t)Endpoint_Read_16_LE() << 8);
|
||||
#else
|
||||
uint16_t PageAddress = Endpoint_Read_16_LE();
|
||||
#endif
|
||||
|
||||
/* Check if the command is a program page command, or a start application command */
|
||||
#if (FLASHEND > 0xFFFF)
|
||||
if ((uint16_t)(PageAddress >> 8) == COMMAND_STARTAPPLICATION)
|
||||
#else
|
||||
if (PageAddress == COMMAND_STARTAPPLICATION)
|
||||
#endif
|
||||
{
|
||||
RunBootloader = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Erase the given FLASH page, ready to be programmed */
|
||||
boot_page_erase(PageAddress);
|
||||
boot_spm_busy_wait();
|
||||
|
||||
/* Write each of the FLASH page's bytes in sequence */
|
||||
for (uint8_t PageWord = 0; PageWord < (SPM_PAGESIZE / 2); PageWord++)
|
||||
{
|
||||
/* Check if endpoint is empty - if so clear it and wait until ready for next packet */
|
||||
if (!(Endpoint_BytesInEndpoint()))
|
||||
{
|
||||
Endpoint_ClearOUT();
|
||||
while (!(Endpoint_IsOUTReceived()));
|
||||
}
|
||||
|
||||
/* Write the next data word to the FLASH page */
|
||||
boot_page_fill(PageAddress + ((uint16_t)PageWord << 1), Endpoint_Read_16_LE());
|
||||
}
|
||||
|
||||
/* Write the filled FLASH page to memory */
|
||||
boot_page_write(PageAddress);
|
||||
boot_spm_busy_wait();
|
||||
|
||||
/* Re-enable RWW section */
|
||||
boot_rww_enable();
|
||||
}
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the HID class bootloader. This file contains the complete bootloader logic.
|
||||
*/
|
||||
|
||||
#include "BootloaderHID.h"
|
||||
|
||||
/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
|
||||
* via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application
|
||||
* started via a forced watchdog reset.
|
||||
*/
|
||||
static bool RunBootloader = true;
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* Setup hardware required for the bootloader */
|
||||
SetupHardware();
|
||||
|
||||
/* Enable global interrupts so that the USB stack can function */
|
||||
sei();
|
||||
|
||||
while (RunBootloader)
|
||||
USB_USBTask();
|
||||
|
||||
/* Disconnect from the host - USB interface will be reset later along with the AVR */
|
||||
USB_Detach();
|
||||
|
||||
/* Enable the watchdog and force a timeout to reset the AVR */
|
||||
wdt_enable(WDTO_250MS);
|
||||
|
||||
for (;;);
|
||||
}
|
||||
|
||||
/** Configures all hardware required for the bootloader. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Relocate the interrupt vector table to the bootloader section */
|
||||
MCUCR = (1 << IVCE);
|
||||
MCUCR = (1 << IVSEL);
|
||||
|
||||
/* Initialize USB subsystem */
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** 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 HID Report Endpoint */
|
||||
Endpoint_ConfigureEndpoint(HID_IN_EPNUM, EP_TYPE_INTERRUPT,
|
||||
ENDPOINT_DIR_IN, HID_IN_EPSIZE,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
}
|
||||
|
||||
/** 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 HID interface */
|
||||
if ((USB_ControlRequest.bmRequestType & (CONTROL_REQTYPE_TYPE | CONTROL_REQTYPE_RECIPIENT)) !=
|
||||
(REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Process HID specific control requests */
|
||||
switch (USB_ControlRequest.bRequest)
|
||||
{
|
||||
case HID_REQ_SetReport:
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Wait until the command has been sent by the host */
|
||||
while (!(Endpoint_IsOUTReceived()));
|
||||
|
||||
/* Read in the write destination address */
|
||||
#if (FLASHEND > 0xFFFF)
|
||||
uint32_t PageAddress = ((uint32_t)Endpoint_Read_16_LE() << 8);
|
||||
#else
|
||||
uint16_t PageAddress = Endpoint_Read_16_LE();
|
||||
#endif
|
||||
|
||||
/* Check if the command is a program page command, or a start application command */
|
||||
#if (FLASHEND > 0xFFFF)
|
||||
if ((uint16_t)(PageAddress >> 8) == COMMAND_STARTAPPLICATION)
|
||||
#else
|
||||
if (PageAddress == COMMAND_STARTAPPLICATION)
|
||||
#endif
|
||||
{
|
||||
RunBootloader = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Erase the given FLASH page, ready to be programmed */
|
||||
boot_page_erase(PageAddress);
|
||||
boot_spm_busy_wait();
|
||||
|
||||
/* Write each of the FLASH page's bytes in sequence */
|
||||
for (uint8_t PageWord = 0; PageWord < (SPM_PAGESIZE / 2); PageWord++)
|
||||
{
|
||||
/* Check if endpoint is empty - if so clear it and wait until ready for next packet */
|
||||
if (!(Endpoint_BytesInEndpoint()))
|
||||
{
|
||||
Endpoint_ClearOUT();
|
||||
while (!(Endpoint_IsOUTReceived()));
|
||||
}
|
||||
|
||||
/* Write the next data word to the FLASH page */
|
||||
boot_page_fill(PageAddress + ((uint16_t)PageWord << 1), Endpoint_Read_16_LE());
|
||||
}
|
||||
|
||||
/* Write the filled FLASH page to memory */
|
||||
boot_page_write(PageAddress);
|
||||
boot_spm_busy_wait();
|
||||
|
||||
/* Re-enable RWW section */
|
||||
boot_rww_enable();
|
||||
}
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for TeensyHID.c.
|
||||
*/
|
||||
|
||||
#ifndef _TEENSYHID_H_
|
||||
#define _TEENSYHID_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/boot.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Bootloader special address to start the user application */
|
||||
#define COMMAND_STARTAPPLICATION 0xFFFF
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
|
||||
void EVENT_USB_Device_ConfigurationChanged(void);
|
||||
void EVENT_USB_Device_UnhandledControlRequest(void);
|
||||
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for TeensyHID.c.
|
||||
*/
|
||||
|
||||
#ifndef _TEENSYHID_H_
|
||||
#define _TEENSYHID_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/boot.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Bootloader special address to start the user application */
|
||||
#define COMMAND_STARTAPPLICATION 0xFFFF
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
|
||||
void EVENT_USB_Device_ConfigurationChanged(void);
|
||||
void EVENT_USB_Device_UnhandledControlRequest(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
/** \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 HID Class USB AVR Bootloader
|
||||
*
|
||||
* \section SSec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* - Series 7 USB AVRs (AT90USBxxx7)
|
||||
* - Series 6 USB AVRs (AT90USBxxx6)
|
||||
* - Series 4 USB AVRs (ATMEGAxxU4)
|
||||
* - Series 2 USB AVRs (AT90USBxx2, ATMEGAxxU2)
|
||||
*
|
||||
* \section SSec_Info USB Information:
|
||||
*
|
||||
* The following table gives a rundown of the USB utilization of this demo.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td><b>USB Mode:</b></td>
|
||||
* <td>Device</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>USB Class:</b></td>
|
||||
* <td>Human Interface Device Class (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 Class Standard \n
|
||||
* Teensy Programming Protocol Specification</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Usable Speeds:</b></td>
|
||||
* <td>Low Speed Mode \n
|
||||
* Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section SSec_Description Project Description:
|
||||
*
|
||||
* This bootloader enumerates to the host as a HID Class device, allowing for device FLASH programming through
|
||||
* the supplied command line software, which is a modified version of Paul's TeensyHID Command Line loader code
|
||||
* from PJRC (used with permission). This bootloader is deliberatley non-compatible with the properietary PJRC
|
||||
* HalfKay bootloader GUI; only the command line interface software accompanying this bootloader will work with it.
|
||||
*
|
||||
* Out of the box this bootloader builds for the USB1287, and will fit into 2KB of bootloader space for the
|
||||
* Series 2 USB AVRs (ATMEGAxxU2, AT90USBxx2) or 4KB of bootloader space for all other models. If you wish to
|
||||
* enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU values in the
|
||||
* accompanying makefile.
|
||||
*
|
||||
* \section Sec_Installation Driver Installation
|
||||
*
|
||||
* This bootloader uses the HID class driver inbuilt into all modern operating systems, thus no additional drivers
|
||||
* need to be supplied for correct operation.
|
||||
*
|
||||
* \section Sec_HostApp Host Controller Application
|
||||
*
|
||||
* Due to licensing issues, the supplied bootloader is compatible with the HalfKay bootloader protocol designed
|
||||
* by PJRC, but is non-compatible with the cross-platform loader GUI. A modified version of the open source
|
||||
* cross-platform TeensyLoader application is supplied, which can be compiled under most operating systems. The
|
||||
* command-line loader application should remain compatible with genuine Teensy boards in addition to boards using
|
||||
* this custom bootloader.
|
||||
*
|
||||
* Once compiled, programs can be loaded into the AVR's FLASH memory through the following example command:
|
||||
* \code
|
||||
* hid_bootloader_cli -mmcu=at90usb1287 Mouse.hex
|
||||
* \endcode
|
||||
*
|
||||
* \section SSec_Options Project Options
|
||||
*
|
||||
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>
|
||||
* None
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
/** \file
|
||||
*
|
||||
* This file contains special DoxyGen information for the generation of the main page and other special
|
||||
* documentation pages. It is not a project source file.
|
||||
*/
|
||||
|
||||
/** \mainpage HID Class USB AVR Bootloader
|
||||
*
|
||||
* \section SSec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* - Series 7 USB AVRs (AT90USBxxx7)
|
||||
* - Series 6 USB AVRs (AT90USBxxx6)
|
||||
* - Series 4 USB AVRs (ATMEGAxxU4)
|
||||
* - Series 2 USB AVRs (AT90USBxx2, ATMEGAxxU2)
|
||||
*
|
||||
* \section SSec_Info USB Information:
|
||||
*
|
||||
* The following table gives a rundown of the USB utilization of this demo.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td><b>USB Mode:</b></td>
|
||||
* <td>Device</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>USB Class:</b></td>
|
||||
* <td>Human Interface Device Class (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 Class Standard \n
|
||||
* Teensy Programming Protocol Specification</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Usable Speeds:</b></td>
|
||||
* <td>Low Speed Mode \n
|
||||
* Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section SSec_Description Project Description:
|
||||
*
|
||||
* This bootloader enumerates to the host as a HID Class device, allowing for device FLASH programming through
|
||||
* the supplied command line software, which is a modified version of Paul's TeensyHID Command Line loader code
|
||||
* from PJRC (used with permission). This bootloader is deliberatley non-compatible with the properietary PJRC
|
||||
* HalfKay bootloader GUI; only the command line interface software accompanying this bootloader will work with it.
|
||||
*
|
||||
* Out of the box this bootloader builds for the USB1287, and will fit into 2KB of bootloader space for the
|
||||
* Series 2 USB AVRs (ATMEGAxxU2, AT90USBxx2) or 4KB of bootloader space for all other models. If you wish to
|
||||
* enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU values in the
|
||||
* accompanying makefile.
|
||||
*
|
||||
* \section Sec_Installation Driver Installation
|
||||
*
|
||||
* This bootloader uses the HID class driver inbuilt into all modern operating systems, thus no additional drivers
|
||||
* need to be supplied for correct operation.
|
||||
*
|
||||
* \section Sec_HostApp Host Controller Application
|
||||
*
|
||||
* Due to licensing issues, the supplied bootloader is compatible with the HalfKay bootloader protocol designed
|
||||
* by PJRC, but is non-compatible with the cross-platform loader GUI. A modified version of the open source
|
||||
* cross-platform TeensyLoader application is supplied, which can be compiled under most operating systems. The
|
||||
* command-line loader application should remain compatible with genuine Teensy boards in addition to boards using
|
||||
* this custom bootloader.
|
||||
*
|
||||
* Once compiled, programs can be loaded into the AVR's FLASH memory through the following example command:
|
||||
* \code
|
||||
* hid_bootloader_cli -mmcu=at90usb1287 Mouse.hex
|
||||
* \endcode
|
||||
*
|
||||
* \section SSec_Options Project Options
|
||||
*
|
||||
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>
|
||||
* None
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
|
||||
@@ -1,186 +1,186 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
||||
* computer-readable structures which the host requests upon device enumeration, to determine
|
||||
* the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
/** HID class report descriptor. This is a special descriptor constructed with values from the
|
||||
* USBIF HID class specification to describe the reports and capabilities of the HID device. This
|
||||
* descriptor is parsed by the host and its contents used to determine what data (and in what encoding)
|
||||
* the device will send, and what it may be sent back from the host. Refer to the HID specification for
|
||||
* more details on HID report descriptors.
|
||||
*/
|
||||
const USB_Descriptor_HIDReport_Datatype_t HIDReport[] =
|
||||
{
|
||||
HID_RI_USAGE_PAGE(16, 0xFFDC), /* Vendor Page 0xDC */
|
||||
HID_RI_USAGE(8, 0xFB), /* Vendor Usage 0xFB */
|
||||
HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */
|
||||
HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
HID_RI_REPORT_COUNT(16, (sizeof(uint16_t) + SPM_PAGESIZE)),
|
||||
HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
|
||||
HID_RI_END_COLLECTION(0),
|
||||
};
|
||||
|
||||
/** 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 DeviceDescriptor =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
|
||||
|
||||
.USBSpecification = VERSION_BCD(01.10),
|
||||
.Class = USB_CSCP_NoDeviceClass,
|
||||
.SubClass = USB_CSCP_NoDeviceSubclass,
|
||||
.Protocol = USB_CSCP_NoDeviceProtocol,
|
||||
|
||||
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
||||
|
||||
.VendorID = 0x03EB,
|
||||
.ProductID = 0x2067,
|
||||
.ReleaseNumber = VERSION_BCD(00.01),
|
||||
|
||||
.ManufacturerStrIndex = NO_DESCRIPTOR,
|
||||
.ProductStrIndex = NO_DESCRIPTOR,
|
||||
.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 ConfigurationDescriptor =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
|
||||
|
||||
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
|
||||
.TotalInterfaces = 1,
|
||||
|
||||
.ConfigurationNumber = 1,
|
||||
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
|
||||
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||
},
|
||||
|
||||
.HID_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 0x00,
|
||||
.AlternateSetting = 0x00,
|
||||
|
||||
.TotalEndpoints = 1,
|
||||
|
||||
.Class = HID_CSCP_HIDClass,
|
||||
.SubClass = HID_CSCP_NonBootSubclass,
|
||||
.Protocol = HID_CSCP_NonBootProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.HID_VendorHID =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
|
||||
|
||||
.HIDSpec = VERSION_BCD(01.11),
|
||||
.CountryCode = 0x00,
|
||||
.TotalReportDescriptors = 1,
|
||||
.HIDReportType = HID_DTYPE_Report,
|
||||
.HIDReportLength = sizeof(HIDReport)
|
||||
},
|
||||
|
||||
.HID_ReportINEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | HID_IN_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = HID_IN_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
};
|
||||
|
||||
/** 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 void* Address = NULL;
|
||||
uint16_t Size = NO_DESCRIPTOR;
|
||||
|
||||
/* If/Else If chain compiles slightly smaller than a switch case */
|
||||
if (DescriptorType == DTYPE_Device)
|
||||
{
|
||||
Address = &DeviceDescriptor;
|
||||
Size = sizeof(USB_Descriptor_Device_t);
|
||||
}
|
||||
else if (DescriptorType == DTYPE_Configuration)
|
||||
{
|
||||
Address = &ConfigurationDescriptor;
|
||||
Size = sizeof(USB_Descriptor_Configuration_t);
|
||||
}
|
||||
else if (DescriptorType == HID_DTYPE_HID)
|
||||
{
|
||||
Address = &ConfigurationDescriptor.HID_VendorHID;
|
||||
Size = sizeof(USB_HID_Descriptor_HID_t);
|
||||
}
|
||||
else
|
||||
{
|
||||
Address = &HIDReport;
|
||||
Size = sizeof(HIDReport);
|
||||
}
|
||||
|
||||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
||||
* computer-readable structures which the host requests upon device enumeration, to determine
|
||||
* the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
/** HID class report descriptor. This is a special descriptor constructed with values from the
|
||||
* USBIF HID class specification to describe the reports and capabilities of the HID device. This
|
||||
* descriptor is parsed by the host and its contents used to determine what data (and in what encoding)
|
||||
* the device will send, and what it may be sent back from the host. Refer to the HID specification for
|
||||
* more details on HID report descriptors.
|
||||
*/
|
||||
const USB_Descriptor_HIDReport_Datatype_t HIDReport[] =
|
||||
{
|
||||
HID_RI_USAGE_PAGE(16, 0xFFDC), /* Vendor Page 0xDC */
|
||||
HID_RI_USAGE(8, 0xFB), /* Vendor Usage 0xFB */
|
||||
HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */
|
||||
HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
HID_RI_REPORT_COUNT(16, (sizeof(uint16_t) + SPM_PAGESIZE)),
|
||||
HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
|
||||
HID_RI_END_COLLECTION(0),
|
||||
};
|
||||
|
||||
/** 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 DeviceDescriptor =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
|
||||
|
||||
.USBSpecification = VERSION_BCD(01.10),
|
||||
.Class = USB_CSCP_NoDeviceClass,
|
||||
.SubClass = USB_CSCP_NoDeviceSubclass,
|
||||
.Protocol = USB_CSCP_NoDeviceProtocol,
|
||||
|
||||
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
||||
|
||||
.VendorID = 0x03EB,
|
||||
.ProductID = 0x2067,
|
||||
.ReleaseNumber = VERSION_BCD(00.01),
|
||||
|
||||
.ManufacturerStrIndex = NO_DESCRIPTOR,
|
||||
.ProductStrIndex = NO_DESCRIPTOR,
|
||||
.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 ConfigurationDescriptor =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
|
||||
|
||||
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
|
||||
.TotalInterfaces = 1,
|
||||
|
||||
.ConfigurationNumber = 1,
|
||||
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
|
||||
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||
},
|
||||
|
||||
.HID_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 0x00,
|
||||
.AlternateSetting = 0x00,
|
||||
|
||||
.TotalEndpoints = 1,
|
||||
|
||||
.Class = HID_CSCP_HIDClass,
|
||||
.SubClass = HID_CSCP_NonBootSubclass,
|
||||
.Protocol = HID_CSCP_NonBootProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.HID_VendorHID =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
|
||||
|
||||
.HIDSpec = VERSION_BCD(01.11),
|
||||
.CountryCode = 0x00,
|
||||
.TotalReportDescriptors = 1,
|
||||
.HIDReportType = HID_DTYPE_Report,
|
||||
.HIDReportLength = sizeof(HIDReport)
|
||||
},
|
||||
|
||||
.HID_ReportINEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | HID_IN_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = HID_IN_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
};
|
||||
|
||||
/** 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 void* Address = NULL;
|
||||
uint16_t Size = NO_DESCRIPTOR;
|
||||
|
||||
/* If/Else If chain compiles slightly smaller than a switch case */
|
||||
if (DescriptorType == DTYPE_Device)
|
||||
{
|
||||
Address = &DeviceDescriptor;
|
||||
Size = sizeof(USB_Descriptor_Device_t);
|
||||
}
|
||||
else if (DescriptorType == DTYPE_Configuration)
|
||||
{
|
||||
Address = &ConfigurationDescriptor;
|
||||
Size = sizeof(USB_Descriptor_Configuration_t);
|
||||
}
|
||||
else if (DescriptorType == HID_DTYPE_HID)
|
||||
{
|
||||
Address = &ConfigurationDescriptor.HID_VendorHID;
|
||||
Size = sizeof(USB_HID_Descriptor_HID_t);
|
||||
}
|
||||
else
|
||||
{
|
||||
Address = &HIDReport;
|
||||
Size = sizeof(HIDReport);
|
||||
}
|
||||
|
||||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for Descriptors.c.
|
||||
*/
|
||||
|
||||
#ifndef _DESCRIPTORS_H_
|
||||
#define _DESCRIPTORS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
/* 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_VendorHID;
|
||||
USB_Descriptor_Endpoint_t HID_ReportINEndpoint;
|
||||
} USB_Descriptor_Configuration_t;
|
||||
|
||||
/* Macros: */
|
||||
/** Endpoint number of the HID data IN endpoint. */
|
||||
#define HID_IN_EPNUM 1
|
||||
|
||||
/** Size in bytes of the HID reporting IN endpoint. */
|
||||
#define HID_IN_EPSIZE 64
|
||||
|
||||
/* 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
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for Descriptors.c.
|
||||
*/
|
||||
|
||||
#ifndef _DESCRIPTORS_H_
|
||||
#define _DESCRIPTORS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
/* 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_VendorHID;
|
||||
USB_Descriptor_Endpoint_t HID_ReportINEndpoint;
|
||||
} USB_Descriptor_Configuration_t;
|
||||
|
||||
/* Macros: */
|
||||
/** Endpoint number of the HID data IN endpoint. */
|
||||
#define HID_IN_EPNUM 1
|
||||
|
||||
/** Size in bytes of the HID reporting IN endpoint. */
|
||||
#define HID_IN_EPSIZE 64
|
||||
|
||||
/* 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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,321 +1,321 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
||||
* computer-readable structures which the host requests upon device enumeration, to determine
|
||||
* the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
/* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
|
||||
* the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
|
||||
* This allows the host to track a device across insertions on different ports, allowing them to retain allocated
|
||||
* resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
|
||||
* so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
|
||||
* from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
|
||||
* port location).
|
||||
*/
|
||||
#if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)
|
||||
#warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.
|
||||
#endif
|
||||
|
||||
/** 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(01.10),
|
||||
.Class = USB_CSCP_IADDeviceClass,
|
||||
.SubClass = USB_CSCP_IADDeviceSubclass,
|
||||
.Protocol = USB_CSCP_IADDeviceProtocol,
|
||||
|
||||
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
||||
|
||||
.VendorID = 0x03EB,
|
||||
.ProductID = 0x2068,
|
||||
.ReleaseNumber = VERSION_BCD(00.01),
|
||||
|
||||
.ManufacturerStrIndex = 0x01,
|
||||
.ProductStrIndex = 0x02,
|
||||
.SerialNumStrIndex = USE_INTERNAL_SERIAL,
|
||||
|
||||
.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 = 3,
|
||||
|
||||
.ConfigurationNumber = 1,
|
||||
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
|
||||
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||
},
|
||||
|
||||
.CDC_IAD =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
|
||||
|
||||
.FirstInterfaceIndex = 0,
|
||||
.TotalInterfaces = 2,
|
||||
|
||||
.Class = CDC_CSCP_CDCClass,
|
||||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.IADStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC_CCI_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 0,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 1,
|
||||
|
||||
.Class = CDC_CSCP_CDCClass,
|
||||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC_Functional_Header =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Header,
|
||||
|
||||
.CDCSpecification = VERSION_BCD(01.10),
|
||||
},
|
||||
|
||||
.CDC_Functional_ACM =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_ACM,
|
||||
|
||||
.Capabilities = 0x06,
|
||||
},
|
||||
|
||||
.CDC_Functional_Union =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Union,
|
||||
|
||||
.MasterInterfaceNumber = 0,
|
||||
.SlaveInterfaceNumber = 1,
|
||||
},
|
||||
|
||||
.CDC_NotificationEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC_NOTIFICATION_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
|
||||
.PollingIntervalMS = 0xFF
|
||||
},
|
||||
|
||||
.CDC_DCI_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 1,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 2,
|
||||
|
||||
.Class = CDC_CSCP_CDCDataClass,
|
||||
.SubClass = CDC_CSCP_NoDataSubclass,
|
||||
.Protocol = CDC_CSCP_NoDataProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC_DataOutEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | CDC_RX_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_TXRX_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.CDC_DataInEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC_TX_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_TXRX_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.MS_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 2,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 2,
|
||||
|
||||
.Class = MS_CSCP_MassStorageClass,
|
||||
.SubClass = MS_CSCP_SCSITransparentSubclass,
|
||||
.Protocol = MS_CSCP_BulkOnlyTransportProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MS_DataInEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | MASS_STORAGE_IN_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.MS_DataOutEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | MASS_STORAGE_OUT_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
}
|
||||
};
|
||||
|
||||
/** 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 =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = {LANGUAGE_ID_ENG}
|
||||
};
|
||||
|
||||
/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
|
||||
* form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
|
||||
* Descriptor.
|
||||
*/
|
||||
const USB_Descriptor_String_t PROGMEM ManufacturerString =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = 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 =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(30), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = L"LUFA CDC and Mass Storage 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 0x00:
|
||||
Address = &LanguageString;
|
||||
Size = pgm_read_byte(&LanguageString.Header.Size);
|
||||
break;
|
||||
case 0x01:
|
||||
Address = &ManufacturerString;
|
||||
Size = pgm_read_byte(&ManufacturerString.Header.Size);
|
||||
break;
|
||||
case 0x02:
|
||||
Address = &ProductString;
|
||||
Size = pgm_read_byte(&ProductString.Header.Size);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
||||
* computer-readable structures which the host requests upon device enumeration, to determine
|
||||
* the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
/* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
|
||||
* the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
|
||||
* This allows the host to track a device across insertions on different ports, allowing them to retain allocated
|
||||
* resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
|
||||
* so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
|
||||
* from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
|
||||
* port location).
|
||||
*/
|
||||
#if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)
|
||||
#warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.
|
||||
#endif
|
||||
|
||||
/** 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(01.10),
|
||||
.Class = USB_CSCP_IADDeviceClass,
|
||||
.SubClass = USB_CSCP_IADDeviceSubclass,
|
||||
.Protocol = USB_CSCP_IADDeviceProtocol,
|
||||
|
||||
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
||||
|
||||
.VendorID = 0x03EB,
|
||||
.ProductID = 0x2068,
|
||||
.ReleaseNumber = VERSION_BCD(00.01),
|
||||
|
||||
.ManufacturerStrIndex = 0x01,
|
||||
.ProductStrIndex = 0x02,
|
||||
.SerialNumStrIndex = USE_INTERNAL_SERIAL,
|
||||
|
||||
.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 = 3,
|
||||
|
||||
.ConfigurationNumber = 1,
|
||||
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
|
||||
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||
},
|
||||
|
||||
.CDC_IAD =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
|
||||
|
||||
.FirstInterfaceIndex = 0,
|
||||
.TotalInterfaces = 2,
|
||||
|
||||
.Class = CDC_CSCP_CDCClass,
|
||||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.IADStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC_CCI_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 0,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 1,
|
||||
|
||||
.Class = CDC_CSCP_CDCClass,
|
||||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC_Functional_Header =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Header,
|
||||
|
||||
.CDCSpecification = VERSION_BCD(01.10),
|
||||
},
|
||||
|
||||
.CDC_Functional_ACM =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_ACM,
|
||||
|
||||
.Capabilities = 0x06,
|
||||
},
|
||||
|
||||
.CDC_Functional_Union =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Union,
|
||||
|
||||
.MasterInterfaceNumber = 0,
|
||||
.SlaveInterfaceNumber = 1,
|
||||
},
|
||||
|
||||
.CDC_NotificationEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC_NOTIFICATION_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
|
||||
.PollingIntervalMS = 0xFF
|
||||
},
|
||||
|
||||
.CDC_DCI_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 1,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 2,
|
||||
|
||||
.Class = CDC_CSCP_CDCDataClass,
|
||||
.SubClass = CDC_CSCP_NoDataSubclass,
|
||||
.Protocol = CDC_CSCP_NoDataProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC_DataOutEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | CDC_RX_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_TXRX_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.CDC_DataInEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC_TX_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_TXRX_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.MS_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 2,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 2,
|
||||
|
||||
.Class = MS_CSCP_MassStorageClass,
|
||||
.SubClass = MS_CSCP_SCSITransparentSubclass,
|
||||
.Protocol = MS_CSCP_BulkOnlyTransportProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MS_DataInEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | MASS_STORAGE_IN_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.MS_DataOutEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | MASS_STORAGE_OUT_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
}
|
||||
};
|
||||
|
||||
/** 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 =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = {LANGUAGE_ID_ENG}
|
||||
};
|
||||
|
||||
/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
|
||||
* form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
|
||||
* Descriptor.
|
||||
*/
|
||||
const USB_Descriptor_String_t PROGMEM ManufacturerString =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = 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 =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(30), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = L"LUFA CDC and Mass Storage 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 0x00:
|
||||
Address = &LanguageString;
|
||||
Size = pgm_read_byte(&LanguageString.Header.Size);
|
||||
break;
|
||||
case 0x01:
|
||||
Address = &ManufacturerString;
|
||||
Size = pgm_read_byte(&ManufacturerString.Header.Size);
|
||||
break;
|
||||
case 0x02:
|
||||
Address = &ProductString;
|
||||
Size = pgm_read_byte(&ProductString.Header.Size);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,104 +1,104 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for Descriptors.c.
|
||||
*/
|
||||
|
||||
#ifndef _DESCRIPTORS_H_
|
||||
#define _DESCRIPTORS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Endpoint number of the CDC device-to-host notification IN endpoint. */
|
||||
#define CDC_NOTIFICATION_EPNUM 1
|
||||
|
||||
/** Endpoint number of the CDC device-to-host data IN endpoint. */
|
||||
#define CDC_TX_EPNUM 2
|
||||
|
||||
/** Endpoint number of the CDC host-to-device data OUT endpoint. */
|
||||
#define CDC_RX_EPNUM 3
|
||||
|
||||
/** Size in bytes of the CDC device-to-host notification IN endpoint. */
|
||||
#define CDC_NOTIFICATION_EPSIZE 8
|
||||
|
||||
/** Size in bytes of the CDC data IN and OUT endpoints. */
|
||||
#define CDC_TXRX_EPSIZE 16
|
||||
|
||||
/** Endpoint number of the Mass Storage device-to-host data IN endpoint. */
|
||||
#define MASS_STORAGE_IN_EPNUM 4
|
||||
|
||||
/** Endpoint number of the Mass Storage host-to-device data OUT endpoint. */
|
||||
#define MASS_STORAGE_OUT_EPNUM 5
|
||||
|
||||
/** Size in bytes of the Mass Storage data endpoints. */
|
||||
#define MASS_STORAGE_IO_EPSIZE 64
|
||||
|
||||
/* 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;
|
||||
|
||||
// CDC Control Interface
|
||||
USB_Descriptor_Interface_Association_t CDC_IAD;
|
||||
USB_Descriptor_Interface_t CDC_CCI_Interface;
|
||||
USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
|
||||
USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
|
||||
USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
|
||||
USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
|
||||
|
||||
// CDC Data Interface
|
||||
USB_Descriptor_Interface_t CDC_DCI_Interface;
|
||||
USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
|
||||
USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
|
||||
|
||||
// Mass Storage Interface
|
||||
USB_Descriptor_Interface_t MS_Interface;
|
||||
USB_Descriptor_Endpoint_t MS_DataInEndpoint;
|
||||
USB_Descriptor_Endpoint_t MS_DataOutEndpoint;
|
||||
} USB_Descriptor_Configuration_t;
|
||||
|
||||
/* 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
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for Descriptors.c.
|
||||
*/
|
||||
|
||||
#ifndef _DESCRIPTORS_H_
|
||||
#define _DESCRIPTORS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Endpoint number of the CDC device-to-host notification IN endpoint. */
|
||||
#define CDC_NOTIFICATION_EPNUM 1
|
||||
|
||||
/** Endpoint number of the CDC device-to-host data IN endpoint. */
|
||||
#define CDC_TX_EPNUM 2
|
||||
|
||||
/** Endpoint number of the CDC host-to-device data OUT endpoint. */
|
||||
#define CDC_RX_EPNUM 3
|
||||
|
||||
/** Size in bytes of the CDC device-to-host notification IN endpoint. */
|
||||
#define CDC_NOTIFICATION_EPSIZE 8
|
||||
|
||||
/** Size in bytes of the CDC data IN and OUT endpoints. */
|
||||
#define CDC_TXRX_EPSIZE 16
|
||||
|
||||
/** Endpoint number of the Mass Storage device-to-host data IN endpoint. */
|
||||
#define MASS_STORAGE_IN_EPNUM 4
|
||||
|
||||
/** Endpoint number of the Mass Storage host-to-device data OUT endpoint. */
|
||||
#define MASS_STORAGE_OUT_EPNUM 5
|
||||
|
||||
/** Size in bytes of the Mass Storage data endpoints. */
|
||||
#define MASS_STORAGE_IO_EPSIZE 64
|
||||
|
||||
/* 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;
|
||||
|
||||
// CDC Control Interface
|
||||
USB_Descriptor_Interface_Association_t CDC_IAD;
|
||||
USB_Descriptor_Interface_t CDC_CCI_Interface;
|
||||
USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
|
||||
USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
|
||||
USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
|
||||
USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
|
||||
|
||||
// CDC Data Interface
|
||||
USB_Descriptor_Interface_t CDC_DCI_Interface;
|
||||
USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
|
||||
USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
|
||||
|
||||
// Mass Storage Interface
|
||||
USB_Descriptor_Interface_t MS_Interface;
|
||||
USB_Descriptor_Endpoint_t MS_DataInEndpoint;
|
||||
USB_Descriptor_Endpoint_t MS_DataOutEndpoint;
|
||||
} USB_Descriptor_Configuration_t;
|
||||
|
||||
/* 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
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,106 +1,106 @@
|
||||
;************************************************************
|
||||
; Windows USB CDC ACM Setup File
|
||||
; Copyright (c) 2000 Microsoft Corporation
|
||||
|
||||
|
||||
[Version]
|
||||
Signature="$Windows NT$"
|
||||
Class=Ports
|
||||
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
|
||||
Provider=%MFGNAME%
|
||||
LayoutFile=layout.inf
|
||||
CatalogFile=%MFGFILENAME%.cat
|
||||
DriverVer=11/15/2007,5.1.2600.0
|
||||
|
||||
[Manufacturer]
|
||||
%MFGNAME%=DeviceList, NTamd64
|
||||
|
||||
[DestinationDirs]
|
||||
DefaultDestDir=12
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Windows 2000/XP/Vista-32bit Sections
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
[DriverInstall.nt]
|
||||
include=mdmcpq.inf
|
||||
CopyFiles=DriverCopyFiles.nt
|
||||
AddReg=DriverInstall.nt.AddReg
|
||||
|
||||
[DriverCopyFiles.nt]
|
||||
usbser.sys,,,0x20
|
||||
|
||||
[DriverInstall.nt.AddReg]
|
||||
HKR,,DevLoader,,*ntkern
|
||||
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
|
||||
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
|
||||
|
||||
[DriverInstall.nt.Services]
|
||||
AddService=usbser, 0x00000002, DriverService.nt
|
||||
|
||||
[DriverService.nt]
|
||||
DisplayName=%SERVICE%
|
||||
ServiceType=1
|
||||
StartType=3
|
||||
ErrorControl=1
|
||||
ServiceBinary=%12%\%DRIVERFILENAME%.sys
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Vista-64bit Sections
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
[DriverInstall.NTamd64]
|
||||
include=mdmcpq.inf
|
||||
CopyFiles=DriverCopyFiles.NTamd64
|
||||
AddReg=DriverInstall.NTamd64.AddReg
|
||||
|
||||
[DriverCopyFiles.NTamd64]
|
||||
%DRIVERFILENAME%.sys,,,0x20
|
||||
|
||||
[DriverInstall.NTamd64.AddReg]
|
||||
HKR,,DevLoader,,*ntkern
|
||||
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
|
||||
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
|
||||
|
||||
[DriverInstall.NTamd64.Services]
|
||||
AddService=usbser, 0x00000002, DriverService.NTamd64
|
||||
|
||||
[DriverService.NTamd64]
|
||||
DisplayName=%SERVICE%
|
||||
ServiceType=1
|
||||
StartType=3
|
||||
ErrorControl=1
|
||||
ServiceBinary=%12%\%DRIVERFILENAME%.sys
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Vendor and Product ID Definitions
|
||||
;------------------------------------------------------------------------------
|
||||
; When developing your USB device, the VID and PID used in the PC side
|
||||
; application program and the firmware on the microcontroller must match.
|
||||
; Modify the below line to use your VID and PID. Use the format as shown below.
|
||||
; Note: One INF file can be used for multiple devices with different VID and PIDs.
|
||||
; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line.
|
||||
;------------------------------------------------------------------------------
|
||||
[SourceDisksFiles]
|
||||
[SourceDisksNames]
|
||||
[DeviceList]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2068&MI_00
|
||||
|
||||
[DeviceList.NTamd64]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2068&MI_00
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; String Definitions
|
||||
;------------------------------------------------------------------------------
|
||||
;Modify these strings to customize your device
|
||||
;------------------------------------------------------------------------------
|
||||
[Strings]
|
||||
MFGFILENAME="CDC_vista"
|
||||
DRIVERFILENAME ="usbser"
|
||||
MFGNAME="http://www.lufa-lib.org"
|
||||
INSTDISK="LUFA CDC/Mass Storage Driver Installer"
|
||||
DESCRIPTION="Communications Port"
|
||||
;************************************************************
|
||||
; Windows USB CDC ACM Setup File
|
||||
; Copyright (c) 2000 Microsoft Corporation
|
||||
|
||||
|
||||
[Version]
|
||||
Signature="$Windows NT$"
|
||||
Class=Ports
|
||||
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
|
||||
Provider=%MFGNAME%
|
||||
LayoutFile=layout.inf
|
||||
CatalogFile=%MFGFILENAME%.cat
|
||||
DriverVer=11/15/2007,5.1.2600.0
|
||||
|
||||
[Manufacturer]
|
||||
%MFGNAME%=DeviceList, NTamd64
|
||||
|
||||
[DestinationDirs]
|
||||
DefaultDestDir=12
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Windows 2000/XP/Vista-32bit Sections
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
[DriverInstall.nt]
|
||||
include=mdmcpq.inf
|
||||
CopyFiles=DriverCopyFiles.nt
|
||||
AddReg=DriverInstall.nt.AddReg
|
||||
|
||||
[DriverCopyFiles.nt]
|
||||
usbser.sys,,,0x20
|
||||
|
||||
[DriverInstall.nt.AddReg]
|
||||
HKR,,DevLoader,,*ntkern
|
||||
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
|
||||
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
|
||||
|
||||
[DriverInstall.nt.Services]
|
||||
AddService=usbser, 0x00000002, DriverService.nt
|
||||
|
||||
[DriverService.nt]
|
||||
DisplayName=%SERVICE%
|
||||
ServiceType=1
|
||||
StartType=3
|
||||
ErrorControl=1
|
||||
ServiceBinary=%12%\%DRIVERFILENAME%.sys
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Vista-64bit Sections
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
[DriverInstall.NTamd64]
|
||||
include=mdmcpq.inf
|
||||
CopyFiles=DriverCopyFiles.NTamd64
|
||||
AddReg=DriverInstall.NTamd64.AddReg
|
||||
|
||||
[DriverCopyFiles.NTamd64]
|
||||
%DRIVERFILENAME%.sys,,,0x20
|
||||
|
||||
[DriverInstall.NTamd64.AddReg]
|
||||
HKR,,DevLoader,,*ntkern
|
||||
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
|
||||
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
|
||||
|
||||
[DriverInstall.NTamd64.Services]
|
||||
AddService=usbser, 0x00000002, DriverService.NTamd64
|
||||
|
||||
[DriverService.NTamd64]
|
||||
DisplayName=%SERVICE%
|
||||
ServiceType=1
|
||||
StartType=3
|
||||
ErrorControl=1
|
||||
ServiceBinary=%12%\%DRIVERFILENAME%.sys
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Vendor and Product ID Definitions
|
||||
;------------------------------------------------------------------------------
|
||||
; When developing your USB device, the VID and PID used in the PC side
|
||||
; application program and the firmware on the microcontroller must match.
|
||||
; Modify the below line to use your VID and PID. Use the format as shown below.
|
||||
; Note: One INF file can be used for multiple devices with different VID and PIDs.
|
||||
; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line.
|
||||
;------------------------------------------------------------------------------
|
||||
[SourceDisksFiles]
|
||||
[SourceDisksNames]
|
||||
[DeviceList]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2068&MI_00
|
||||
|
||||
[DeviceList.NTamd64]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2068&MI_00
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; String Definitions
|
||||
;------------------------------------------------------------------------------
|
||||
;Modify these strings to customize your device
|
||||
;------------------------------------------------------------------------------
|
||||
[Strings]
|
||||
MFGFILENAME="CDC_vista"
|
||||
DRIVERFILENAME ="usbser"
|
||||
MFGNAME="http://www.lufa-lib.org"
|
||||
INSTDISK="LUFA CDC/Mass Storage Driver Installer"
|
||||
DESCRIPTION="Communications Port"
|
||||
SERVICE="USB RS-232 Emulation Driver"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,85 +1,85 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for DataflashManager.c.
|
||||
*/
|
||||
|
||||
#ifndef _DATAFLASH_MANAGER_H_
|
||||
#define _DATAFLASH_MANAGER_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "VirtualSerialMassStorage.h"
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Common/Common.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Dataflash.h>
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if (DATAFLASH_PAGE_SIZE % 16)
|
||||
#error Dataflash page size must be a multiple of 16 bytes.
|
||||
#endif
|
||||
|
||||
/* Defines: */
|
||||
/** Total number of bytes of the storage medium, comprised of one or more Dataflash ICs. */
|
||||
#define VIRTUAL_MEMORY_BYTES ((uint32_t)DATAFLASH_PAGES * DATAFLASH_PAGE_SIZE * DATAFLASH_TOTALCHIPS)
|
||||
|
||||
/** Block size of the device. This is kept at 512 to remain compatible with the OS despite the underlying
|
||||
* storage media (Dataflash) using a different native block size. Do not change this value.
|
||||
*/
|
||||
#define VIRTUAL_MEMORY_BLOCK_SIZE 512
|
||||
|
||||
/** Total number of blocks of the virtual memory for reporting to the host as the device's total capacity. Do not
|
||||
* change this value; change VIRTUAL_MEMORY_BYTES instead to alter the media size.
|
||||
*/
|
||||
#define VIRTUAL_MEMORY_BLOCKS (VIRTUAL_MEMORY_BYTES / VIRTUAL_MEMORY_BLOCK_SIZE)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
||||
const uint32_t BlockAddress,
|
||||
uint16_t TotalBlocks);
|
||||
void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
||||
const uint32_t BlockAddress,
|
||||
uint16_t TotalBlocks);
|
||||
void DataflashManager_WriteBlocks_RAM(const uint32_t BlockAddress,
|
||||
uint16_t TotalBlocks,
|
||||
uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);
|
||||
void DataflashManager_ReadBlocks_RAM(const uint32_t BlockAddress,
|
||||
uint16_t TotalBlocks,
|
||||
uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);
|
||||
void DataflashManager_ResetDataflashProtections(void);
|
||||
bool DataflashManager_CheckDataflashOperation(void);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for DataflashManager.c.
|
||||
*/
|
||||
|
||||
#ifndef _DATAFLASH_MANAGER_H_
|
||||
#define _DATAFLASH_MANAGER_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "VirtualSerialMassStorage.h"
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Common/Common.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Dataflash.h>
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if (DATAFLASH_PAGE_SIZE % 16)
|
||||
#error Dataflash page size must be a multiple of 16 bytes.
|
||||
#endif
|
||||
|
||||
/* Defines: */
|
||||
/** Total number of bytes of the storage medium, comprised of one or more Dataflash ICs. */
|
||||
#define VIRTUAL_MEMORY_BYTES ((uint32_t)DATAFLASH_PAGES * DATAFLASH_PAGE_SIZE * DATAFLASH_TOTALCHIPS)
|
||||
|
||||
/** Block size of the device. This is kept at 512 to remain compatible with the OS despite the underlying
|
||||
* storage media (Dataflash) using a different native block size. Do not change this value.
|
||||
*/
|
||||
#define VIRTUAL_MEMORY_BLOCK_SIZE 512
|
||||
|
||||
/** Total number of blocks of the virtual memory for reporting to the host as the device's total capacity. Do not
|
||||
* change this value; change VIRTUAL_MEMORY_BYTES instead to alter the media size.
|
||||
*/
|
||||
#define VIRTUAL_MEMORY_BLOCKS (VIRTUAL_MEMORY_BYTES / VIRTUAL_MEMORY_BLOCK_SIZE)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
||||
const uint32_t BlockAddress,
|
||||
uint16_t TotalBlocks);
|
||||
void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
||||
const uint32_t BlockAddress,
|
||||
uint16_t TotalBlocks);
|
||||
void DataflashManager_WriteBlocks_RAM(const uint32_t BlockAddress,
|
||||
uint16_t TotalBlocks,
|
||||
uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);
|
||||
void DataflashManager_ReadBlocks_RAM(const uint32_t BlockAddress,
|
||||
uint16_t TotalBlocks,
|
||||
uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);
|
||||
void DataflashManager_ResetDataflashProtections(void);
|
||||
bool DataflashManager_CheckDataflashOperation(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,347 +1,347 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* SCSI command processing routines, for SCSI commands issued by the host. Mass Storage
|
||||
* devices use a thin "Bulk-Only Transport" protocol for issuing commands and status information,
|
||||
* which wrap around standard SCSI device commands for controlling the actual storage medium.
|
||||
*/
|
||||
|
||||
#define INCLUDE_FROM_SCSI_C
|
||||
#include "SCSI.h"
|
||||
|
||||
/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
|
||||
* features and capabilities.
|
||||
*/
|
||||
static const SCSI_Inquiry_Response_t InquiryData =
|
||||
{
|
||||
.DeviceType = DEVICE_TYPE_BLOCK,
|
||||
.PeripheralQualifier = 0,
|
||||
|
||||
.Removable = true,
|
||||
|
||||
.Version = 0,
|
||||
|
||||
.ResponseDataFormat = 2,
|
||||
.NormACA = false,
|
||||
.TrmTsk = false,
|
||||
.AERC = false,
|
||||
|
||||
.AdditionalLength = 0x1F,
|
||||
|
||||
.SoftReset = false,
|
||||
.CmdQue = false,
|
||||
.Linked = false,
|
||||
.Sync = false,
|
||||
.WideBus16Bit = false,
|
||||
.WideBus32Bit = false,
|
||||
.RelAddr = false,
|
||||
|
||||
.VendorID = "LUFA",
|
||||
.ProductID = "Dataflash Disk",
|
||||
.RevisionID = {'0','.','0','0'},
|
||||
};
|
||||
|
||||
/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
|
||||
* command is issued. This gives information on exactly why the last command failed to complete.
|
||||
*/
|
||||
static SCSI_Request_Sense_Response_t SenseData =
|
||||
{
|
||||
.ResponseCode = 0x70,
|
||||
.AdditionalLength = 0x0A,
|
||||
};
|
||||
|
||||
|
||||
/** Main routine to process the SCSI command located in the Command Block Wrapper read from the host. This dispatches
|
||||
* to the appropriate SCSI command handling routine if the issued command is supported by the device, else it returns
|
||||
* a command failure due to a ILLEGAL REQUEST.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise
|
||||
*/
|
||||
bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
bool CommandSuccess = false;
|
||||
|
||||
/* Run the appropriate SCSI command hander function based on the passed command */
|
||||
switch (MSInterfaceInfo->State.CommandBlock.SCSICommandData[0])
|
||||
{
|
||||
case SCSI_CMD_INQUIRY:
|
||||
CommandSuccess = SCSI_Command_Inquiry(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_REQUEST_SENSE:
|
||||
CommandSuccess = SCSI_Command_Request_Sense(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_READ_CAPACITY_10:
|
||||
CommandSuccess = SCSI_Command_Read_Capacity_10(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_SEND_DIAGNOSTIC:
|
||||
CommandSuccess = SCSI_Command_Send_Diagnostic(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_WRITE_10:
|
||||
CommandSuccess = SCSI_Command_ReadWrite_10(MSInterfaceInfo, DATA_WRITE);
|
||||
break;
|
||||
case SCSI_CMD_READ_10:
|
||||
CommandSuccess = SCSI_Command_ReadWrite_10(MSInterfaceInfo, DATA_READ);
|
||||
break;
|
||||
case SCSI_CMD_MODE_SENSE_6:
|
||||
CommandSuccess = SCSI_Command_ModeSense_6(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_TEST_UNIT_READY:
|
||||
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
case SCSI_CMD_VERIFY_10:
|
||||
/* These commands should just succeed, no handling required */
|
||||
CommandSuccess = true;
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
|
||||
break;
|
||||
default:
|
||||
/* Update the SENSE key to reflect the invalid command */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
|
||||
SCSI_ASENSE_INVALID_COMMAND,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if command was successfully processed */
|
||||
if (CommandSuccess)
|
||||
{
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_GOOD,
|
||||
SCSI_ASENSE_NO_ADDITIONAL_INFORMATION,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI INQUIRY command. This command returns information about the device's features
|
||||
* and capabilities to the host.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
uint16_t AllocationLength = SwapEndian_16(*(uint16_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[3]);
|
||||
uint16_t BytesTransferred = MIN(AllocationLength, sizeof(InquiryData));
|
||||
|
||||
/* Only the standard INQUIRY data is supported, check if any optional INQUIRY bits set */
|
||||
if ((MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & ((1 << 0) | (1 << 1))) ||
|
||||
MSInterfaceInfo->State.CommandBlock.SCSICommandData[2])
|
||||
{
|
||||
/* Optional but unsupported bits set - update the SENSE key and fail the request */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
|
||||
SCSI_ASENSE_INVALID_FIELD_IN_CDB,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Endpoint_Write_Stream_LE(&InquiryData, BytesTransferred, NULL);
|
||||
|
||||
/* Pad out remaining bytes with 0x00 */
|
||||
Endpoint_Null_Stream((AllocationLength - BytesTransferred), NULL);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Succeed the command and update the bytes transferred counter */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI REQUEST SENSE command. This command returns information about the last issued command,
|
||||
* including the error code and additional error information so that the host can determine why a command failed to complete.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
uint8_t AllocationLength = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];
|
||||
uint8_t BytesTransferred = MIN(AllocationLength, sizeof(SenseData));
|
||||
|
||||
Endpoint_Write_Stream_LE(&SenseData, BytesTransferred, NULL);
|
||||
Endpoint_Null_Stream((AllocationLength - BytesTransferred), NULL);
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Succeed the command and update the bytes transferred counter */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI READ CAPACITY (10) command. This command returns information about the device's capacity
|
||||
* on the selected Logical Unit (drive), as a number of OS-sized blocks.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
uint32_t LastBlockAddressInLUN = (LUN_MEDIA_BLOCKS - 1);
|
||||
uint32_t MediaBlockSize = VIRTUAL_MEMORY_BLOCK_SIZE;
|
||||
|
||||
Endpoint_Write_Stream_BE(&LastBlockAddressInLUN, sizeof(LastBlockAddressInLUN), NULL);
|
||||
Endpoint_Write_Stream_BE(&MediaBlockSize, sizeof(MediaBlockSize), NULL);
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Succeed the command and update the bytes transferred counter */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 8;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI SEND DIAGNOSTIC command. This command performs a quick check of the Dataflash ICs on the
|
||||
* board, and indicates if they are present and functioning correctly. Only the Self-Test portion of the diagnostic command is
|
||||
* supported.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
/* Check to see if the SELF TEST bit is not set */
|
||||
if (!(MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & (1 << 2)))
|
||||
{
|
||||
/* Only self-test supported - update SENSE key and fail the command */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
|
||||
SCSI_ASENSE_INVALID_FIELD_IN_CDB,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check to see if all attached Dataflash ICs are functional */
|
||||
if (!(DataflashManager_CheckDataflashOperation()))
|
||||
{
|
||||
/* Update SENSE key with a hardware error condition and return command fail */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR,
|
||||
SCSI_ASENSE_NO_ADDITIONAL_INFORMATION,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Succeed the command and update the bytes transferred counter */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI READ (10) or WRITE (10) command. This command reads in the block start address
|
||||
* and total number of blocks to process, then calls the appropriate low-level Dataflash routine to handle the actual
|
||||
* reading and writing of the data.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
* \param[in] IsDataRead Indicates if the command is a READ (10) command or WRITE (10) command (DATA_READ or DATA_WRITE)
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
||||
const bool IsDataRead)
|
||||
{
|
||||
uint32_t BlockAddress;
|
||||
uint16_t TotalBlocks;
|
||||
|
||||
/* Check if the disk is write protected or not */
|
||||
if ((IsDataRead == DATA_WRITE) && DISK_READ_ONLY)
|
||||
{
|
||||
/* Block address is invalid, update SENSE key and return command fail */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_DATA_PROTECT,
|
||||
SCSI_ASENSE_WRITE_PROTECTED,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Load in the 32-bit block address (SCSI uses big-endian, so have to reverse the byte order) */
|
||||
BlockAddress = SwapEndian_32(*(uint32_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[2]);
|
||||
|
||||
/* Load in the 16-bit total blocks (SCSI uses big-endian, so have to reverse the byte order) */
|
||||
TotalBlocks = SwapEndian_16(*(uint16_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[7]);
|
||||
|
||||
/* Check if the block address is outside the maximum allowable value for the LUN */
|
||||
if (BlockAddress >= LUN_MEDIA_BLOCKS)
|
||||
{
|
||||
/* Block address is invalid, update SENSE key and return command fail */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
|
||||
SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if (TOTAL_LUNS > 1)
|
||||
/* Adjust the given block address to the real media address based on the selected LUN */
|
||||
BlockAddress += ((uint32_t)MSInterfaceInfo->State.CommandBlock.LUN * LUN_MEDIA_BLOCKS);
|
||||
#endif
|
||||
|
||||
/* Determine if the packet is a READ (10) or WRITE (10) command, call appropriate function */
|
||||
if (IsDataRead == DATA_READ)
|
||||
DataflashManager_ReadBlocks(MSInterfaceInfo, BlockAddress, TotalBlocks);
|
||||
else
|
||||
DataflashManager_WriteBlocks(MSInterfaceInfo, BlockAddress, TotalBlocks);
|
||||
|
||||
/* Update the bytes transferred counter and succeed the command */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI MODE SENSE (6) command. This command returns various informational pages about
|
||||
* the SCSI device, as well as the device's Write Protect status.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
/* Send an empty header response with the Write Protect flag status */
|
||||
Endpoint_Write_8(0x00);
|
||||
Endpoint_Write_8(0x00);
|
||||
Endpoint_Write_8(DISK_READ_ONLY ? 0x80 : 0x00);
|
||||
Endpoint_Write_8(0x00);
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Update the bytes transferred counter and succeed the command */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 4;
|
||||
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* SCSI command processing routines, for SCSI commands issued by the host. Mass Storage
|
||||
* devices use a thin "Bulk-Only Transport" protocol for issuing commands and status information,
|
||||
* which wrap around standard SCSI device commands for controlling the actual storage medium.
|
||||
*/
|
||||
|
||||
#define INCLUDE_FROM_SCSI_C
|
||||
#include "SCSI.h"
|
||||
|
||||
/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
|
||||
* features and capabilities.
|
||||
*/
|
||||
static const SCSI_Inquiry_Response_t InquiryData =
|
||||
{
|
||||
.DeviceType = DEVICE_TYPE_BLOCK,
|
||||
.PeripheralQualifier = 0,
|
||||
|
||||
.Removable = true,
|
||||
|
||||
.Version = 0,
|
||||
|
||||
.ResponseDataFormat = 2,
|
||||
.NormACA = false,
|
||||
.TrmTsk = false,
|
||||
.AERC = false,
|
||||
|
||||
.AdditionalLength = 0x1F,
|
||||
|
||||
.SoftReset = false,
|
||||
.CmdQue = false,
|
||||
.Linked = false,
|
||||
.Sync = false,
|
||||
.WideBus16Bit = false,
|
||||
.WideBus32Bit = false,
|
||||
.RelAddr = false,
|
||||
|
||||
.VendorID = "LUFA",
|
||||
.ProductID = "Dataflash Disk",
|
||||
.RevisionID = {'0','.','0','0'},
|
||||
};
|
||||
|
||||
/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
|
||||
* command is issued. This gives information on exactly why the last command failed to complete.
|
||||
*/
|
||||
static SCSI_Request_Sense_Response_t SenseData =
|
||||
{
|
||||
.ResponseCode = 0x70,
|
||||
.AdditionalLength = 0x0A,
|
||||
};
|
||||
|
||||
|
||||
/** Main routine to process the SCSI command located in the Command Block Wrapper read from the host. This dispatches
|
||||
* to the appropriate SCSI command handling routine if the issued command is supported by the device, else it returns
|
||||
* a command failure due to a ILLEGAL REQUEST.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise
|
||||
*/
|
||||
bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
bool CommandSuccess = false;
|
||||
|
||||
/* Run the appropriate SCSI command hander function based on the passed command */
|
||||
switch (MSInterfaceInfo->State.CommandBlock.SCSICommandData[0])
|
||||
{
|
||||
case SCSI_CMD_INQUIRY:
|
||||
CommandSuccess = SCSI_Command_Inquiry(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_REQUEST_SENSE:
|
||||
CommandSuccess = SCSI_Command_Request_Sense(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_READ_CAPACITY_10:
|
||||
CommandSuccess = SCSI_Command_Read_Capacity_10(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_SEND_DIAGNOSTIC:
|
||||
CommandSuccess = SCSI_Command_Send_Diagnostic(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_WRITE_10:
|
||||
CommandSuccess = SCSI_Command_ReadWrite_10(MSInterfaceInfo, DATA_WRITE);
|
||||
break;
|
||||
case SCSI_CMD_READ_10:
|
||||
CommandSuccess = SCSI_Command_ReadWrite_10(MSInterfaceInfo, DATA_READ);
|
||||
break;
|
||||
case SCSI_CMD_MODE_SENSE_6:
|
||||
CommandSuccess = SCSI_Command_ModeSense_6(MSInterfaceInfo);
|
||||
break;
|
||||
case SCSI_CMD_TEST_UNIT_READY:
|
||||
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
case SCSI_CMD_VERIFY_10:
|
||||
/* These commands should just succeed, no handling required */
|
||||
CommandSuccess = true;
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
|
||||
break;
|
||||
default:
|
||||
/* Update the SENSE key to reflect the invalid command */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
|
||||
SCSI_ASENSE_INVALID_COMMAND,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if command was successfully processed */
|
||||
if (CommandSuccess)
|
||||
{
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_GOOD,
|
||||
SCSI_ASENSE_NO_ADDITIONAL_INFORMATION,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI INQUIRY command. This command returns information about the device's features
|
||||
* and capabilities to the host.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
uint16_t AllocationLength = SwapEndian_16(*(uint16_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[3]);
|
||||
uint16_t BytesTransferred = MIN(AllocationLength, sizeof(InquiryData));
|
||||
|
||||
/* Only the standard INQUIRY data is supported, check if any optional INQUIRY bits set */
|
||||
if ((MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & ((1 << 0) | (1 << 1))) ||
|
||||
MSInterfaceInfo->State.CommandBlock.SCSICommandData[2])
|
||||
{
|
||||
/* Optional but unsupported bits set - update the SENSE key and fail the request */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
|
||||
SCSI_ASENSE_INVALID_FIELD_IN_CDB,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Endpoint_Write_Stream_LE(&InquiryData, BytesTransferred, NULL);
|
||||
|
||||
/* Pad out remaining bytes with 0x00 */
|
||||
Endpoint_Null_Stream((AllocationLength - BytesTransferred), NULL);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Succeed the command and update the bytes transferred counter */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI REQUEST SENSE command. This command returns information about the last issued command,
|
||||
* including the error code and additional error information so that the host can determine why a command failed to complete.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
uint8_t AllocationLength = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];
|
||||
uint8_t BytesTransferred = MIN(AllocationLength, sizeof(SenseData));
|
||||
|
||||
Endpoint_Write_Stream_LE(&SenseData, BytesTransferred, NULL);
|
||||
Endpoint_Null_Stream((AllocationLength - BytesTransferred), NULL);
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Succeed the command and update the bytes transferred counter */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI READ CAPACITY (10) command. This command returns information about the device's capacity
|
||||
* on the selected Logical Unit (drive), as a number of OS-sized blocks.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
uint32_t LastBlockAddressInLUN = (LUN_MEDIA_BLOCKS - 1);
|
||||
uint32_t MediaBlockSize = VIRTUAL_MEMORY_BLOCK_SIZE;
|
||||
|
||||
Endpoint_Write_Stream_BE(&LastBlockAddressInLUN, sizeof(LastBlockAddressInLUN), NULL);
|
||||
Endpoint_Write_Stream_BE(&MediaBlockSize, sizeof(MediaBlockSize), NULL);
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Succeed the command and update the bytes transferred counter */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 8;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI SEND DIAGNOSTIC command. This command performs a quick check of the Dataflash ICs on the
|
||||
* board, and indicates if they are present and functioning correctly. Only the Self-Test portion of the diagnostic command is
|
||||
* supported.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
/* Check to see if the SELF TEST bit is not set */
|
||||
if (!(MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & (1 << 2)))
|
||||
{
|
||||
/* Only self-test supported - update SENSE key and fail the command */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
|
||||
SCSI_ASENSE_INVALID_FIELD_IN_CDB,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check to see if all attached Dataflash ICs are functional */
|
||||
if (!(DataflashManager_CheckDataflashOperation()))
|
||||
{
|
||||
/* Update SENSE key with a hardware error condition and return command fail */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR,
|
||||
SCSI_ASENSE_NO_ADDITIONAL_INFORMATION,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Succeed the command and update the bytes transferred counter */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI READ (10) or WRITE (10) command. This command reads in the block start address
|
||||
* and total number of blocks to process, then calls the appropriate low-level Dataflash routine to handle the actual
|
||||
* reading and writing of the data.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
* \param[in] IsDataRead Indicates if the command is a READ (10) command or WRITE (10) command (DATA_READ or DATA_WRITE)
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
||||
const bool IsDataRead)
|
||||
{
|
||||
uint32_t BlockAddress;
|
||||
uint16_t TotalBlocks;
|
||||
|
||||
/* Check if the disk is write protected or not */
|
||||
if ((IsDataRead == DATA_WRITE) && DISK_READ_ONLY)
|
||||
{
|
||||
/* Block address is invalid, update SENSE key and return command fail */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_DATA_PROTECT,
|
||||
SCSI_ASENSE_WRITE_PROTECTED,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Load in the 32-bit block address (SCSI uses big-endian, so have to reverse the byte order) */
|
||||
BlockAddress = SwapEndian_32(*(uint32_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[2]);
|
||||
|
||||
/* Load in the 16-bit total blocks (SCSI uses big-endian, so have to reverse the byte order) */
|
||||
TotalBlocks = SwapEndian_16(*(uint16_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[7]);
|
||||
|
||||
/* Check if the block address is outside the maximum allowable value for the LUN */
|
||||
if (BlockAddress >= LUN_MEDIA_BLOCKS)
|
||||
{
|
||||
/* Block address is invalid, update SENSE key and return command fail */
|
||||
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
|
||||
SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE,
|
||||
SCSI_ASENSEQ_NO_QUALIFIER);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if (TOTAL_LUNS > 1)
|
||||
/* Adjust the given block address to the real media address based on the selected LUN */
|
||||
BlockAddress += ((uint32_t)MSInterfaceInfo->State.CommandBlock.LUN * LUN_MEDIA_BLOCKS);
|
||||
#endif
|
||||
|
||||
/* Determine if the packet is a READ (10) or WRITE (10) command, call appropriate function */
|
||||
if (IsDataRead == DATA_READ)
|
||||
DataflashManager_ReadBlocks(MSInterfaceInfo, BlockAddress, TotalBlocks);
|
||||
else
|
||||
DataflashManager_WriteBlocks(MSInterfaceInfo, BlockAddress, TotalBlocks);
|
||||
|
||||
/* Update the bytes transferred counter and succeed the command */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Command processing for an issued SCSI MODE SENSE (6) command. This command returns various informational pages about
|
||||
* the SCSI device, as well as the device's Write Protect status.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
|
||||
*
|
||||
* \return Boolean true if the command completed successfully, false otherwise.
|
||||
*/
|
||||
static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
/* Send an empty header response with the Write Protect flag status */
|
||||
Endpoint_Write_8(0x00);
|
||||
Endpoint_Write_8(0x00);
|
||||
Endpoint_Write_8(DISK_READ_ONLY ? 0x80 : 0x00);
|
||||
Endpoint_Write_8(0x00);
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Update the bytes transferred counter and succeed the command */
|
||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 4;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for SCSI.c.
|
||||
*/
|
||||
|
||||
#ifndef _SCSI_H_
|
||||
#define _SCSI_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "VirtualSerialMassStorage.h"
|
||||
#include "Descriptors.h"
|
||||
#include "DataflashManager.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Macro to set the current SCSI sense data to the given key, additional sense code and additional sense qualifier. This
|
||||
* is for convenience, as it allows for all three sense values (returned upon request to the host to give information about
|
||||
* the last command failure) in a quick and easy manner.
|
||||
*
|
||||
* \param[in] Key New SCSI sense key to set the sense code to
|
||||
* \param[in] Acode New SCSI additional sense key to set the additional sense code to
|
||||
* \param[in] Aqual New SCSI additional sense key qualifier to set the additional sense qualifier code to
|
||||
*/
|
||||
#define SCSI_SET_SENSE(Key, Acode, Aqual) MACROS{ SenseData.SenseKey = (Key); \
|
||||
SenseData.AdditionalSenseCode = (Acode); \
|
||||
SenseData.AdditionalSenseQualifier = (Aqual); }MACROE
|
||||
|
||||
/** Macro for the \ref SCSI_Command_ReadWrite_10() function, to indicate that data is to be read from the storage medium. */
|
||||
#define DATA_READ true
|
||||
|
||||
/** Macro for the \ref SCSI_Command_ReadWrite_10() function, to indicate that data is to be written to the storage medium. */
|
||||
#define DATA_WRITE false
|
||||
|
||||
/** Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a Block Media device. */
|
||||
#define DEVICE_TYPE_BLOCK 0x00
|
||||
|
||||
/** Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a CD-ROM device. */
|
||||
#define DEVICE_TYPE_CDROM 0x05
|
||||
|
||||
/* Function Prototypes: */
|
||||
bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
|
||||
#if defined(INCLUDE_FROM_SCSI_C)
|
||||
static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
||||
const bool IsDataRead);
|
||||
static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for SCSI.c.
|
||||
*/
|
||||
|
||||
#ifndef _SCSI_H_
|
||||
#define _SCSI_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "VirtualSerialMassStorage.h"
|
||||
#include "Descriptors.h"
|
||||
#include "DataflashManager.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Macro to set the current SCSI sense data to the given key, additional sense code and additional sense qualifier. This
|
||||
* is for convenience, as it allows for all three sense values (returned upon request to the host to give information about
|
||||
* the last command failure) in a quick and easy manner.
|
||||
*
|
||||
* \param[in] Key New SCSI sense key to set the sense code to
|
||||
* \param[in] Acode New SCSI additional sense key to set the additional sense code to
|
||||
* \param[in] Aqual New SCSI additional sense key qualifier to set the additional sense qualifier code to
|
||||
*/
|
||||
#define SCSI_SET_SENSE(Key, Acode, Aqual) MACROS{ SenseData.SenseKey = (Key); \
|
||||
SenseData.AdditionalSenseCode = (Acode); \
|
||||
SenseData.AdditionalSenseQualifier = (Aqual); }MACROE
|
||||
|
||||
/** Macro for the \ref SCSI_Command_ReadWrite_10() function, to indicate that data is to be read from the storage medium. */
|
||||
#define DATA_READ true
|
||||
|
||||
/** Macro for the \ref SCSI_Command_ReadWrite_10() function, to indicate that data is to be written to the storage medium. */
|
||||
#define DATA_WRITE false
|
||||
|
||||
/** Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a Block Media device. */
|
||||
#define DEVICE_TYPE_BLOCK 0x00
|
||||
|
||||
/** Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a CD-ROM device. */
|
||||
#define DEVICE_TYPE_CDROM 0x05
|
||||
|
||||
/* Function Prototypes: */
|
||||
bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
|
||||
#if defined(INCLUDE_FROM_SCSI_C)
|
||||
static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
||||
const bool IsDataRead);
|
||||
static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,213 +1,213 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the VirtualSerialMassStorage demo. This file contains the main tasks of
|
||||
* the demo and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "VirtualSerialMassStorage.h"
|
||||
|
||||
/** LUFA CDC Class driver interface configuration and state information. This structure is
|
||||
* passed to all CDC Class driver functions, so that multiple instances of the same class
|
||||
* within a device can be differentiated from one another.
|
||||
*/
|
||||
USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.ControlInterfaceNumber = 0,
|
||||
|
||||
.DataINEndpointNumber = CDC_TX_EPNUM,
|
||||
.DataINEndpointSize = CDC_TXRX_EPSIZE,
|
||||
.DataINEndpointDoubleBank = false,
|
||||
|
||||
.DataOUTEndpointNumber = CDC_RX_EPNUM,
|
||||
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
|
||||
.DataOUTEndpointDoubleBank = false,
|
||||
|
||||
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
|
||||
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
|
||||
.NotificationEndpointDoubleBank = false,
|
||||
},
|
||||
};
|
||||
|
||||
/** LUFA Mass Storage Class driver interface configuration and state information. This structure is
|
||||
* passed to all Mass Storage Class driver functions, so that multiple instances of the same class
|
||||
* within a device can be differentiated from one another.
|
||||
*/
|
||||
USB_ClassInfo_MS_Device_t Disk_MS_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.InterfaceNumber = 2,
|
||||
|
||||
.DataINEndpointNumber = MASS_STORAGE_IN_EPNUM,
|
||||
.DataINEndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||||
.DataINEndpointDoubleBank = false,
|
||||
|
||||
.DataOUTEndpointNumber = MASS_STORAGE_OUT_EPNUM,
|
||||
.DataOUTEndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||||
.DataOUTEndpointDoubleBank = false,
|
||||
|
||||
.TotalLUNs = TOTAL_LUNS,
|
||||
},
|
||||
};
|
||||
|
||||
/** Standard file stream for the CDC interface when set up, so that the virtual CDC COM port can be
|
||||
* used like any regular character stream in the C APIs
|
||||
*/
|
||||
static FILE USBSerialStream;
|
||||
|
||||
|
||||
/** 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();
|
||||
|
||||
/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
|
||||
CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
CheckJoystickMovement();
|
||||
|
||||
/* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
|
||||
CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
|
||||
|
||||
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
|
||||
MS_Device_USBTask(&Disk_MS_Interface);
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
Joystick_Init();
|
||||
SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
|
||||
Dataflash_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Clear Dataflash sector protections, if enabled */
|
||||
DataflashManager_ResetDataflashProtections();
|
||||
}
|
||||
|
||||
/** Checks for changes in the position of the board joystick, sending strings to the host upon each change. */
|
||||
void CheckJoystickMovement(void)
|
||||
{
|
||||
uint8_t JoyStatus_LCL = Joystick_GetStatus();
|
||||
char* ReportString = NULL;
|
||||
static bool ActionSent = false;
|
||||
|
||||
if (JoyStatus_LCL & JOY_UP)
|
||||
ReportString = "Joystick Up\r\n";
|
||||
else if (JoyStatus_LCL & JOY_DOWN)
|
||||
ReportString = "Joystick Down\r\n";
|
||||
else if (JoyStatus_LCL & JOY_LEFT)
|
||||
ReportString = "Joystick Left\r\n";
|
||||
else if (JoyStatus_LCL & JOY_RIGHT)
|
||||
ReportString = "Joystick Right\r\n";
|
||||
else if (JoyStatus_LCL & JOY_PRESS)
|
||||
ReportString = "Joystick Pressed\r\n";
|
||||
else
|
||||
ActionSent = false;
|
||||
|
||||
if ((ReportString != NULL) && (ActionSent == false))
|
||||
{
|
||||
ActionSent = true;
|
||||
|
||||
/* Write the string to the virtual COM port via the created character stream */
|
||||
fputs(ReportString, &USBSerialStream);
|
||||
|
||||
/* Alternatively, without the stream: */
|
||||
// CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
|
||||
ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);
|
||||
|
||||
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)
|
||||
{
|
||||
CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
|
||||
MS_Device_ProcessControlRequest(&Disk_MS_Interface);
|
||||
}
|
||||
|
||||
/** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
|
||||
*/
|
||||
bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
bool CommandSuccess;
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||||
CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
|
||||
return CommandSuccess;
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the VirtualSerialMassStorage demo. This file contains the main tasks of
|
||||
* the demo and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "VirtualSerialMassStorage.h"
|
||||
|
||||
/** LUFA CDC Class driver interface configuration and state information. This structure is
|
||||
* passed to all CDC Class driver functions, so that multiple instances of the same class
|
||||
* within a device can be differentiated from one another.
|
||||
*/
|
||||
USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.ControlInterfaceNumber = 0,
|
||||
|
||||
.DataINEndpointNumber = CDC_TX_EPNUM,
|
||||
.DataINEndpointSize = CDC_TXRX_EPSIZE,
|
||||
.DataINEndpointDoubleBank = false,
|
||||
|
||||
.DataOUTEndpointNumber = CDC_RX_EPNUM,
|
||||
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
|
||||
.DataOUTEndpointDoubleBank = false,
|
||||
|
||||
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
|
||||
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
|
||||
.NotificationEndpointDoubleBank = false,
|
||||
},
|
||||
};
|
||||
|
||||
/** LUFA Mass Storage Class driver interface configuration and state information. This structure is
|
||||
* passed to all Mass Storage Class driver functions, so that multiple instances of the same class
|
||||
* within a device can be differentiated from one another.
|
||||
*/
|
||||
USB_ClassInfo_MS_Device_t Disk_MS_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.InterfaceNumber = 2,
|
||||
|
||||
.DataINEndpointNumber = MASS_STORAGE_IN_EPNUM,
|
||||
.DataINEndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||||
.DataINEndpointDoubleBank = false,
|
||||
|
||||
.DataOUTEndpointNumber = MASS_STORAGE_OUT_EPNUM,
|
||||
.DataOUTEndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||||
.DataOUTEndpointDoubleBank = false,
|
||||
|
||||
.TotalLUNs = TOTAL_LUNS,
|
||||
},
|
||||
};
|
||||
|
||||
/** Standard file stream for the CDC interface when set up, so that the virtual CDC COM port can be
|
||||
* used like any regular character stream in the C APIs
|
||||
*/
|
||||
static FILE USBSerialStream;
|
||||
|
||||
|
||||
/** 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();
|
||||
|
||||
/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
|
||||
CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
CheckJoystickMovement();
|
||||
|
||||
/* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
|
||||
CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
|
||||
|
||||
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
|
||||
MS_Device_USBTask(&Disk_MS_Interface);
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
Joystick_Init();
|
||||
SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
|
||||
Dataflash_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Clear Dataflash sector protections, if enabled */
|
||||
DataflashManager_ResetDataflashProtections();
|
||||
}
|
||||
|
||||
/** Checks for changes in the position of the board joystick, sending strings to the host upon each change. */
|
||||
void CheckJoystickMovement(void)
|
||||
{
|
||||
uint8_t JoyStatus_LCL = Joystick_GetStatus();
|
||||
char* ReportString = NULL;
|
||||
static bool ActionSent = false;
|
||||
|
||||
if (JoyStatus_LCL & JOY_UP)
|
||||
ReportString = "Joystick Up\r\n";
|
||||
else if (JoyStatus_LCL & JOY_DOWN)
|
||||
ReportString = "Joystick Down\r\n";
|
||||
else if (JoyStatus_LCL & JOY_LEFT)
|
||||
ReportString = "Joystick Left\r\n";
|
||||
else if (JoyStatus_LCL & JOY_RIGHT)
|
||||
ReportString = "Joystick Right\r\n";
|
||||
else if (JoyStatus_LCL & JOY_PRESS)
|
||||
ReportString = "Joystick Pressed\r\n";
|
||||
else
|
||||
ActionSent = false;
|
||||
|
||||
if ((ReportString != NULL) && (ActionSent == false))
|
||||
{
|
||||
ActionSent = true;
|
||||
|
||||
/* Write the string to the virtual COM port via the created character stream */
|
||||
fputs(ReportString, &USBSerialStream);
|
||||
|
||||
/* Alternatively, without the stream: */
|
||||
// CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
|
||||
ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);
|
||||
|
||||
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)
|
||||
{
|
||||
CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
|
||||
MS_Device_ProcessControlRequest(&Disk_MS_Interface);
|
||||
}
|
||||
|
||||
/** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
|
||||
*
|
||||
* \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
|
||||
*/
|
||||
bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||
{
|
||||
bool CommandSuccess;
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||||
CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
|
||||
return CommandSuccess;
|
||||
}
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for VirtualSerial.c.
|
||||
*/
|
||||
|
||||
#ifndef _VIRTUALSERIAL_H_
|
||||
#define _VIRTUALSERIAL_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 "Lib/SCSI.h"
|
||||
#include "Lib/DataflashManager.h"
|
||||
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/USB/USB.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)
|
||||
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
|
||||
#define LEDMASK_USB_BUSY LEDS_LED2
|
||||
|
||||
/** Total number of logical drives within the device - must be non-zero. */
|
||||
#define TOTAL_LUNS 1
|
||||
|
||||
/** Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device. */
|
||||
#define LUN_MEDIA_BLOCKS (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)
|
||||
|
||||
/** Indicates if the disk is write protected or not. */
|
||||
#define DISK_READ_ONLY false
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void CheckJoystickMovement(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);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for VirtualSerial.c.
|
||||
*/
|
||||
|
||||
#ifndef _VIRTUALSERIAL_H_
|
||||
#define _VIRTUALSERIAL_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 "Lib/SCSI.h"
|
||||
#include "Lib/DataflashManager.h"
|
||||
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/USB/USB.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)
|
||||
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
|
||||
#define LEDMASK_USB_BUSY LEDS_LED2
|
||||
|
||||
/** Total number of logical drives within the device - must be non-zero. */
|
||||
#define TOTAL_LUNS 1
|
||||
|
||||
/** Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device. */
|
||||
#define LUN_MEDIA_BLOCKS (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)
|
||||
|
||||
/** Indicates if the disk is write protected or not. */
|
||||
#define DISK_READ_ONLY false
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void CheckJoystickMovement(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);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
/** \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 Communications Device Class (Virtual Serial Port) and Mass Storage Demo
|
||||
*
|
||||
* \section Sec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* - Series 7 USB AVRs (AT90USBxxx7)
|
||||
* - Series 6 USB AVRs (AT90USBxxx6)
|
||||
* - Series 4 USB AVRs (ATMEGAxxU4)
|
||||
*
|
||||
* \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>Communications Device Class (CDC) \n
|
||||
* Mass Storage Device</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>USB Subclass:</b></td>
|
||||
* <td>Abstract Control Model (ACM) \n
|
||||
* Bulk-Only Transport</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Relevant Standards:</b></td>
|
||||
* <td>USBIF CDC Class Standard \n
|
||||
* USBIF Mass Storage Standard \n
|
||||
* USB Bulk-Only Transport Standard \n
|
||||
* SCSI Primary Commands Specification \n
|
||||
* SCSI Block Commands Specification</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Usable Speeds:</b></td>
|
||||
* <td>Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section Sec_Description Project Description:
|
||||
*
|
||||
* Combined Communications Device Class/Mass Storage demonstration application.
|
||||
* This gives a simple reference application for implementing a combined
|
||||
* CDC and Mass Storage device acting as a both a virtual serial port and a flash
|
||||
* drive. Joystick actions are transmitted to the host as strings, and data can be
|
||||
* written to or read from the exposed flash drive interface in the same manner as
|
||||
* other USB flash drives. The device does not respond to serial data sent from the
|
||||
* host.
|
||||
*
|
||||
* After running this demo for the first time on a new computer,
|
||||
* you will need to supply the .INF file located in this demo
|
||||
* project's directory as the device's driver when running under
|
||||
* Windows. This will enable Windows to use its inbuilt CDC drivers,
|
||||
* negating the need for custom drivers for the device. Other
|
||||
* Operating Systems should automatically use their own inbuilt
|
||||
* CDC-ACM drivers.
|
||||
*
|
||||
* \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>
|
||||
* <td><b>Define Name:</b></td>
|
||||
* <td><b>Location:</b></td>
|
||||
* <td><b>Description:</b></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>TOTAL_LUNS</td>
|
||||
* <td>MassStorage.h</td>
|
||||
* <td>Total number of Logical Units (drives) in the device. The total device capacity is shared equally between each drive -
|
||||
* this can be set to any positive non-zero amount.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* This file contains special DoxyGen information for the generation of the main page and other special
|
||||
* documentation pages. It is not a project source file.
|
||||
*/
|
||||
|
||||
/** \mainpage Communications Device Class (Virtual Serial Port) and Mass Storage Demo
|
||||
*
|
||||
* \section Sec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* - Series 7 USB AVRs (AT90USBxxx7)
|
||||
* - Series 6 USB AVRs (AT90USBxxx6)
|
||||
* - Series 4 USB AVRs (ATMEGAxxU4)
|
||||
*
|
||||
* \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>Communications Device Class (CDC) \n
|
||||
* Mass Storage Device</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>USB Subclass:</b></td>
|
||||
* <td>Abstract Control Model (ACM) \n
|
||||
* Bulk-Only Transport</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Relevant Standards:</b></td>
|
||||
* <td>USBIF CDC Class Standard \n
|
||||
* USBIF Mass Storage Standard \n
|
||||
* USB Bulk-Only Transport Standard \n
|
||||
* SCSI Primary Commands Specification \n
|
||||
* SCSI Block Commands Specification</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Usable Speeds:</b></td>
|
||||
* <td>Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section Sec_Description Project Description:
|
||||
*
|
||||
* Combined Communications Device Class/Mass Storage demonstration application.
|
||||
* This gives a simple reference application for implementing a combined
|
||||
* CDC and Mass Storage device acting as a both a virtual serial port and a flash
|
||||
* drive. Joystick actions are transmitted to the host as strings, and data can be
|
||||
* written to or read from the exposed flash drive interface in the same manner as
|
||||
* other USB flash drives. The device does not respond to serial data sent from the
|
||||
* host.
|
||||
*
|
||||
* After running this demo for the first time on a new computer,
|
||||
* you will need to supply the .INF file located in this demo
|
||||
* project's directory as the device's driver when running under
|
||||
* Windows. This will enable Windows to use its inbuilt CDC drivers,
|
||||
* negating the need for custom drivers for the device. Other
|
||||
* Operating Systems should automatically use their own inbuilt
|
||||
* CDC-ACM drivers.
|
||||
*
|
||||
* \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>
|
||||
* <td><b>Define Name:</b></td>
|
||||
* <td><b>Location:</b></td>
|
||||
* <td><b>Description:</b></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>TOTAL_LUNS</td>
|
||||
* <td>MassStorage.h</td>
|
||||
* <td>Total number of Logical Units (drives) in the device. The total device capacity is shared equally between each drive -
|
||||
* this can be set to any positive non-zero amount.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,441 +1,441 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#include "TestAndMeasurement.h"
|
||||
|
||||
/** Contains the (usually static) capabilities of the TMC device. This table is requested by the
|
||||
* host upon enumeration to give it information on what features of the Test and Measurement USB
|
||||
* Class the device supports.
|
||||
*/
|
||||
TMC_Capabilities_t Capabilities =
|
||||
{
|
||||
.Status = TMC_STATUS_SUCCESS,
|
||||
.TMCVersion = VERSION_BCD(1.00),
|
||||
|
||||
.Interface =
|
||||
{
|
||||
.ListenOnly = false,
|
||||
.TalkOnly = false,
|
||||
.PulseIndicateSupported = false,
|
||||
},
|
||||
|
||||
.Device =
|
||||
{
|
||||
.SupportsAbortINOnMatch = false,
|
||||
},
|
||||
};
|
||||
|
||||
/** Current TMC control request that is being processed */
|
||||
static uint8_t RequestInProgress = 0;
|
||||
|
||||
/** Stream callback abort flag for bulk IN data */
|
||||
static bool IsTMCBulkINReset = false;
|
||||
|
||||
/** Stream callback abort flag for bulk OUT data */
|
||||
static bool IsTMCBulkOUTReset = false;
|
||||
|
||||
/** Last used tag value for data transfers */
|
||||
static uint8_t CurrentTransferTag = 0;
|
||||
|
||||
/** Length of last data transfer, for reporting to the host in case an in-progress transfer is aborted */
|
||||
static uint32_t LastTransferLength = 0;
|
||||
|
||||
/** 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);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
TMC_Task();
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
|
||||
* starts the library USB task to begin the enumeration and USB management process.
|
||||
*/
|
||||
void EVENT_USB_Device_Connect(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
|
||||
* the status LEDs and stops the USB management and CDC management tasks.
|
||||
*/
|
||||
void EVENT_USB_Device_Disconnect(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
|
||||
* of the USB device after enumeration - the device endpoints are configured and the CDC management task started.
|
||||
*/
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
bool ConfigSuccess = true;
|
||||
|
||||
/* Setup TMC In, Out and Notification Endpoints */
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
||||
TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
|
||||
TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
|
||||
TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate endpoint configuration success or failure */
|
||||
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
uint8_t TMCRequestStatus = TMC_STATUS_SUCCESS;
|
||||
|
||||
/* Process TMC specific control requests */
|
||||
switch (USB_ControlRequest.bRequest)
|
||||
{
|
||||
case Req_InitiateAbortBulkOut:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
|
||||
{
|
||||
/* Check that no split transaction is already in progress and the data transfer tag is valid */
|
||||
if (RequestInProgress != 0)
|
||||
{
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_IN_PROGRESS;
|
||||
}
|
||||
else if (USB_ControlRequest.wValue != CurrentTransferTag)
|
||||
{
|
||||
TMCRequestStatus = TMC_STATUS_TRANSFER_NOT_IN_PROGRESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Indicate that all in-progress/pending data OUT requests should be aborted */
|
||||
IsTMCBulkOUTReset = true;
|
||||
|
||||
/* Save the split request for later checking when a new request is received */
|
||||
RequestInProgress = Req_InitiateAbortBulkOut;
|
||||
}
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response byte */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_CheckAbortBulkOutStatus:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
|
||||
{
|
||||
/* Check that an ABORT BULK OUT transaction has been requested and that the request has completed */
|
||||
if (RequestInProgress != Req_InitiateAbortBulkOut)
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS;
|
||||
else if (IsTMCBulkOUTReset)
|
||||
TMCRequestStatus = TMC_STATUS_PENDING;
|
||||
else
|
||||
RequestInProgress = 0;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response bytes */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
Endpoint_Write_16_LE(0);
|
||||
Endpoint_Write_32_LE(LastTransferLength);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_InitiateAbortBulkIn:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
|
||||
{
|
||||
/* Check that no split transaction is already in progress and the data transfer tag is valid */
|
||||
if (RequestInProgress != 0)
|
||||
{
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_IN_PROGRESS;
|
||||
}
|
||||
else if (USB_ControlRequest.wValue != CurrentTransferTag)
|
||||
{
|
||||
TMCRequestStatus = TMC_STATUS_TRANSFER_NOT_IN_PROGRESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Indicate that all in-progress/pending data IN requests should be aborted */
|
||||
IsTMCBulkINReset = true;
|
||||
|
||||
/* Save the split request for later checking when a new request is received */
|
||||
RequestInProgress = Req_InitiateAbortBulkIn;
|
||||
}
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response bytes */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
Endpoint_Write_8(CurrentTransferTag);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_CheckAbortBulkInStatus:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
|
||||
{
|
||||
/* Check that an ABORT BULK IN transaction has been requested and that the request has completed */
|
||||
if (RequestInProgress != Req_InitiateAbortBulkIn)
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS;
|
||||
else if (IsTMCBulkINReset)
|
||||
TMCRequestStatus = TMC_STATUS_PENDING;
|
||||
else
|
||||
RequestInProgress = 0;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response bytes */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
Endpoint_Write_16_LE(0);
|
||||
Endpoint_Write_32_LE(LastTransferLength);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_InitiateClear:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Check that no split transaction is already in progress */
|
||||
if (RequestInProgress != 0)
|
||||
{
|
||||
Endpoint_Write_8(TMC_STATUS_SPLIT_IN_PROGRESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Indicate that all in-progress/pending data IN and OUT requests should be aborted */
|
||||
IsTMCBulkINReset = true;
|
||||
IsTMCBulkOUTReset = true;
|
||||
|
||||
/* Save the split request for later checking when a new request is received */
|
||||
RequestInProgress = Req_InitiateClear;
|
||||
}
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response byte */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_CheckClearStatus:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Check that a CLEAR transaction has been requested and that the request has completed */
|
||||
if (RequestInProgress != Req_InitiateClear)
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS;
|
||||
else if (IsTMCBulkINReset || IsTMCBulkOUTReset)
|
||||
TMCRequestStatus = TMC_STATUS_PENDING;
|
||||
else
|
||||
RequestInProgress = 0;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response bytes */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
Endpoint_Write_8(0);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_GetCapabilities:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the device capabilities to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&Capabilities, sizeof(TMC_Capabilities_t));
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Function to manage TMC data transmission and reception to and from the host. */
|
||||
void TMC_Task(void)
|
||||
{
|
||||
/* Device must be connected and configured for the task to run */
|
||||
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||
return;
|
||||
|
||||
TMC_MessageHeader_t MessageHeader;
|
||||
uint16_t BytesTransferred;
|
||||
|
||||
/* Try to read in a TMC message from the interface, process if one is available */
|
||||
if (ReadTMCHeader(&MessageHeader))
|
||||
{
|
||||
/* Indicate busy */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||||
|
||||
switch (MessageHeader.MessageID)
|
||||
{
|
||||
case TMC_MESSAGEID_DEV_DEP_MSG_OUT:
|
||||
BytesTransferred = 0;
|
||||
while (Endpoint_Discard_Stream(MessageHeader.TransferSize, &BytesTransferred) ==
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer)
|
||||
{
|
||||
if (IsTMCBulkOUTReset)
|
||||
break;
|
||||
}
|
||||
LastTransferLength = BytesTransferred;
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
break;
|
||||
case TMC_MESSAGEID_DEV_DEP_MSG_IN:
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
char MessageData[] = "TMC Class Test";
|
||||
|
||||
MessageHeader.TransferSize = strlen(MessageData);
|
||||
MessageHeader.MessageIDSpecific.DeviceOUT.LastMessageTransaction = true;
|
||||
WriteTMCHeader(&MessageHeader);
|
||||
|
||||
BytesTransferred = 0;
|
||||
while (Endpoint_Write_Stream_LE(MessageData, MessageHeader.TransferSize, &BytesTransferred) ==
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer)
|
||||
{
|
||||
if (IsTMCBulkINReset)
|
||||
break;
|
||||
}
|
||||
LastTransferLength = BytesTransferred;
|
||||
|
||||
Endpoint_ClearIN();
|
||||
break;
|
||||
default:
|
||||
Endpoint_StallTransaction();
|
||||
break;
|
||||
}
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/* All pending data has been processed - reset the data abort flags */
|
||||
IsTMCBulkINReset = false;
|
||||
IsTMCBulkOUTReset = false;
|
||||
}
|
||||
|
||||
/** Attempts to read in the TMC message header from the TMC interface.
|
||||
*
|
||||
* \param[out] MessageHeader Pointer to a location where the read header (if any) should be stored
|
||||
*
|
||||
* \return Boolean true if a header was read, false otherwise
|
||||
*/
|
||||
bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader)
|
||||
{
|
||||
uint16_t BytesTransferred;
|
||||
uint8_t ErrorCode;
|
||||
|
||||
/* Select the Data Out endpoint */
|
||||
Endpoint_SelectEndpoint(TMC_OUT_EPNUM);
|
||||
|
||||
/* Abort if no command has been sent from the host */
|
||||
if (!(Endpoint_IsOUTReceived()))
|
||||
return false;
|
||||
|
||||
/* Read in the header of the command from the host */
|
||||
BytesTransferred = 0;
|
||||
while ((ErrorCode = Endpoint_Read_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred)) ==
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer)
|
||||
{
|
||||
if (IsTMCBulkOUTReset)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Store the new command tag value for later use */
|
||||
CurrentTransferTag = MessageHeader->Tag;
|
||||
|
||||
/* Indicate if the command has been aborted or not */
|
||||
return (!(IsTMCBulkOUTReset) && (ErrorCode == ENDPOINT_RWSTREAM_NoError));
|
||||
}
|
||||
|
||||
bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader)
|
||||
{
|
||||
uint16_t BytesTransferred;
|
||||
uint8_t ErrorCode;
|
||||
|
||||
/* Set the message tag of the command header */
|
||||
MessageHeader->Tag = CurrentTransferTag;
|
||||
MessageHeader->InverseTag = ~CurrentTransferTag;
|
||||
|
||||
/* Select the Data In endpoint */
|
||||
Endpoint_SelectEndpoint(TMC_IN_EPNUM);
|
||||
|
||||
/* Send the command header to the host */
|
||||
BytesTransferred = 0;
|
||||
while ((ErrorCode = Endpoint_Write_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred)) ==
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer)
|
||||
{
|
||||
if (IsTMCBulkINReset)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Indicate if the command has been aborted or not */
|
||||
return (!(IsTMCBulkINReset) && (ErrorCode == ENDPOINT_RWSTREAM_NoError));
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#include "TestAndMeasurement.h"
|
||||
|
||||
/** Contains the (usually static) capabilities of the TMC device. This table is requested by the
|
||||
* host upon enumeration to give it information on what features of the Test and Measurement USB
|
||||
* Class the device supports.
|
||||
*/
|
||||
TMC_Capabilities_t Capabilities =
|
||||
{
|
||||
.Status = TMC_STATUS_SUCCESS,
|
||||
.TMCVersion = VERSION_BCD(1.00),
|
||||
|
||||
.Interface =
|
||||
{
|
||||
.ListenOnly = false,
|
||||
.TalkOnly = false,
|
||||
.PulseIndicateSupported = false,
|
||||
},
|
||||
|
||||
.Device =
|
||||
{
|
||||
.SupportsAbortINOnMatch = false,
|
||||
},
|
||||
};
|
||||
|
||||
/** Current TMC control request that is being processed */
|
||||
static uint8_t RequestInProgress = 0;
|
||||
|
||||
/** Stream callback abort flag for bulk IN data */
|
||||
static bool IsTMCBulkINReset = false;
|
||||
|
||||
/** Stream callback abort flag for bulk OUT data */
|
||||
static bool IsTMCBulkOUTReset = false;
|
||||
|
||||
/** Last used tag value for data transfers */
|
||||
static uint8_t CurrentTransferTag = 0;
|
||||
|
||||
/** Length of last data transfer, for reporting to the host in case an in-progress transfer is aborted */
|
||||
static uint32_t LastTransferLength = 0;
|
||||
|
||||
/** 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);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
TMC_Task();
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
|
||||
* starts the library USB task to begin the enumeration and USB management process.
|
||||
*/
|
||||
void EVENT_USB_Device_Connect(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
|
||||
* the status LEDs and stops the USB management and CDC management tasks.
|
||||
*/
|
||||
void EVENT_USB_Device_Disconnect(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
|
||||
* of the USB device after enumeration - the device endpoints are configured and the CDC management task started.
|
||||
*/
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
bool ConfigSuccess = true;
|
||||
|
||||
/* Setup TMC In, Out and Notification Endpoints */
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
||||
TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
|
||||
TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
|
||||
TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate endpoint configuration success or failure */
|
||||
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
uint8_t TMCRequestStatus = TMC_STATUS_SUCCESS;
|
||||
|
||||
/* Process TMC specific control requests */
|
||||
switch (USB_ControlRequest.bRequest)
|
||||
{
|
||||
case Req_InitiateAbortBulkOut:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
|
||||
{
|
||||
/* Check that no split transaction is already in progress and the data transfer tag is valid */
|
||||
if (RequestInProgress != 0)
|
||||
{
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_IN_PROGRESS;
|
||||
}
|
||||
else if (USB_ControlRequest.wValue != CurrentTransferTag)
|
||||
{
|
||||
TMCRequestStatus = TMC_STATUS_TRANSFER_NOT_IN_PROGRESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Indicate that all in-progress/pending data OUT requests should be aborted */
|
||||
IsTMCBulkOUTReset = true;
|
||||
|
||||
/* Save the split request for later checking when a new request is received */
|
||||
RequestInProgress = Req_InitiateAbortBulkOut;
|
||||
}
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response byte */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_CheckAbortBulkOutStatus:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
|
||||
{
|
||||
/* Check that an ABORT BULK OUT transaction has been requested and that the request has completed */
|
||||
if (RequestInProgress != Req_InitiateAbortBulkOut)
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS;
|
||||
else if (IsTMCBulkOUTReset)
|
||||
TMCRequestStatus = TMC_STATUS_PENDING;
|
||||
else
|
||||
RequestInProgress = 0;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response bytes */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
Endpoint_Write_16_LE(0);
|
||||
Endpoint_Write_32_LE(LastTransferLength);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_InitiateAbortBulkIn:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
|
||||
{
|
||||
/* Check that no split transaction is already in progress and the data transfer tag is valid */
|
||||
if (RequestInProgress != 0)
|
||||
{
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_IN_PROGRESS;
|
||||
}
|
||||
else if (USB_ControlRequest.wValue != CurrentTransferTag)
|
||||
{
|
||||
TMCRequestStatus = TMC_STATUS_TRANSFER_NOT_IN_PROGRESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Indicate that all in-progress/pending data IN requests should be aborted */
|
||||
IsTMCBulkINReset = true;
|
||||
|
||||
/* Save the split request for later checking when a new request is received */
|
||||
RequestInProgress = Req_InitiateAbortBulkIn;
|
||||
}
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response bytes */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
Endpoint_Write_8(CurrentTransferTag);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_CheckAbortBulkInStatus:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
|
||||
{
|
||||
/* Check that an ABORT BULK IN transaction has been requested and that the request has completed */
|
||||
if (RequestInProgress != Req_InitiateAbortBulkIn)
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS;
|
||||
else if (IsTMCBulkINReset)
|
||||
TMCRequestStatus = TMC_STATUS_PENDING;
|
||||
else
|
||||
RequestInProgress = 0;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response bytes */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
Endpoint_Write_16_LE(0);
|
||||
Endpoint_Write_32_LE(LastTransferLength);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_InitiateClear:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Check that no split transaction is already in progress */
|
||||
if (RequestInProgress != 0)
|
||||
{
|
||||
Endpoint_Write_8(TMC_STATUS_SPLIT_IN_PROGRESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Indicate that all in-progress/pending data IN and OUT requests should be aborted */
|
||||
IsTMCBulkINReset = true;
|
||||
IsTMCBulkOUTReset = true;
|
||||
|
||||
/* Save the split request for later checking when a new request is received */
|
||||
RequestInProgress = Req_InitiateClear;
|
||||
}
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response byte */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_CheckClearStatus:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Check that a CLEAR transaction has been requested and that the request has completed */
|
||||
if (RequestInProgress != Req_InitiateClear)
|
||||
TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS;
|
||||
else if (IsTMCBulkINReset || IsTMCBulkOUTReset)
|
||||
TMCRequestStatus = TMC_STATUS_PENDING;
|
||||
else
|
||||
RequestInProgress = 0;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the request response bytes */
|
||||
Endpoint_Write_8(TMCRequestStatus);
|
||||
Endpoint_Write_8(0);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case Req_GetCapabilities:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the device capabilities to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&Capabilities, sizeof(TMC_Capabilities_t));
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Function to manage TMC data transmission and reception to and from the host. */
|
||||
void TMC_Task(void)
|
||||
{
|
||||
/* Device must be connected and configured for the task to run */
|
||||
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||
return;
|
||||
|
||||
TMC_MessageHeader_t MessageHeader;
|
||||
uint16_t BytesTransferred;
|
||||
|
||||
/* Try to read in a TMC message from the interface, process if one is available */
|
||||
if (ReadTMCHeader(&MessageHeader))
|
||||
{
|
||||
/* Indicate busy */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||||
|
||||
switch (MessageHeader.MessageID)
|
||||
{
|
||||
case TMC_MESSAGEID_DEV_DEP_MSG_OUT:
|
||||
BytesTransferred = 0;
|
||||
while (Endpoint_Discard_Stream(MessageHeader.TransferSize, &BytesTransferred) ==
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer)
|
||||
{
|
||||
if (IsTMCBulkOUTReset)
|
||||
break;
|
||||
}
|
||||
LastTransferLength = BytesTransferred;
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
break;
|
||||
case TMC_MESSAGEID_DEV_DEP_MSG_IN:
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
char MessageData[] = "TMC Class Test";
|
||||
|
||||
MessageHeader.TransferSize = strlen(MessageData);
|
||||
MessageHeader.MessageIDSpecific.DeviceOUT.LastMessageTransaction = true;
|
||||
WriteTMCHeader(&MessageHeader);
|
||||
|
||||
BytesTransferred = 0;
|
||||
while (Endpoint_Write_Stream_LE(MessageData, MessageHeader.TransferSize, &BytesTransferred) ==
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer)
|
||||
{
|
||||
if (IsTMCBulkINReset)
|
||||
break;
|
||||
}
|
||||
LastTransferLength = BytesTransferred;
|
||||
|
||||
Endpoint_ClearIN();
|
||||
break;
|
||||
default:
|
||||
Endpoint_StallTransaction();
|
||||
break;
|
||||
}
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/* All pending data has been processed - reset the data abort flags */
|
||||
IsTMCBulkINReset = false;
|
||||
IsTMCBulkOUTReset = false;
|
||||
}
|
||||
|
||||
/** Attempts to read in the TMC message header from the TMC interface.
|
||||
*
|
||||
* \param[out] MessageHeader Pointer to a location where the read header (if any) should be stored
|
||||
*
|
||||
* \return Boolean true if a header was read, false otherwise
|
||||
*/
|
||||
bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader)
|
||||
{
|
||||
uint16_t BytesTransferred;
|
||||
uint8_t ErrorCode;
|
||||
|
||||
/* Select the Data Out endpoint */
|
||||
Endpoint_SelectEndpoint(TMC_OUT_EPNUM);
|
||||
|
||||
/* Abort if no command has been sent from the host */
|
||||
if (!(Endpoint_IsOUTReceived()))
|
||||
return false;
|
||||
|
||||
/* Read in the header of the command from the host */
|
||||
BytesTransferred = 0;
|
||||
while ((ErrorCode = Endpoint_Read_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred)) ==
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer)
|
||||
{
|
||||
if (IsTMCBulkOUTReset)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Store the new command tag value for later use */
|
||||
CurrentTransferTag = MessageHeader->Tag;
|
||||
|
||||
/* Indicate if the command has been aborted or not */
|
||||
return (!(IsTMCBulkOUTReset) && (ErrorCode == ENDPOINT_RWSTREAM_NoError));
|
||||
}
|
||||
|
||||
bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader)
|
||||
{
|
||||
uint16_t BytesTransferred;
|
||||
uint8_t ErrorCode;
|
||||
|
||||
/* Set the message tag of the command header */
|
||||
MessageHeader->Tag = CurrentTransferTag;
|
||||
MessageHeader->InverseTag = ~CurrentTransferTag;
|
||||
|
||||
/* Select the Data In endpoint */
|
||||
Endpoint_SelectEndpoint(TMC_IN_EPNUM);
|
||||
|
||||
/* Send the command header to the host */
|
||||
BytesTransferred = 0;
|
||||
while ((ErrorCode = Endpoint_Write_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred)) ==
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer)
|
||||
{
|
||||
if (IsTMCBulkINReset)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Indicate if the command has been aborted or not */
|
||||
return (!(IsTMCBulkINReset) && (ErrorCode == ENDPOINT_RWSTREAM_NoError));
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Android Accessory Mode utility functions, for the configuration of an attached
|
||||
* Android device into Android Accessory Mode ready for general communication.
|
||||
*/
|
||||
|
||||
#include "AndroidAccessoryCommands.h"
|
||||
|
||||
uint8_t Android_GetAccessoryProtocol(uint16_t* const Protocol)
|
||||
{
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE),
|
||||
.bRequest = ANDROID_Req_GetAccessoryProtocol,
|
||||
.wValue = 0,
|
||||
.wIndex = 0,
|
||||
.wLength = sizeof(uint16_t),
|
||||
};
|
||||
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
return USB_Host_SendControlRequest(Protocol);
|
||||
}
|
||||
|
||||
uint8_t Android_SendString(const uint8_t StringIndex,
|
||||
char* String)
|
||||
{
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
|
||||
.bRequest = ANDROID_Req_SendString,
|
||||
.wValue = 0,
|
||||
.wIndex = StringIndex,
|
||||
.wLength = (strlen(String) + 1),
|
||||
};
|
||||
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
return USB_Host_SendControlRequest(String);
|
||||
}
|
||||
|
||||
uint8_t Android_StartAccessoryMode(void)
|
||||
{
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
|
||||
.bRequest = ANDROID_Req_StartAccessoryMode,
|
||||
.wValue = 0,
|
||||
.wIndex = 0,
|
||||
.wLength = 0,
|
||||
};
|
||||
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
return USB_Host_SendControlRequest(NULL);
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Android Accessory Mode utility functions, for the configuration of an attached
|
||||
* Android device into Android Accessory Mode ready for general communication.
|
||||
*/
|
||||
|
||||
#include "AndroidAccessoryCommands.h"
|
||||
|
||||
uint8_t Android_GetAccessoryProtocol(uint16_t* const Protocol)
|
||||
{
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE),
|
||||
.bRequest = ANDROID_Req_GetAccessoryProtocol,
|
||||
.wValue = 0,
|
||||
.wIndex = 0,
|
||||
.wLength = sizeof(uint16_t),
|
||||
};
|
||||
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
return USB_Host_SendControlRequest(Protocol);
|
||||
}
|
||||
|
||||
uint8_t Android_SendString(const uint8_t StringIndex,
|
||||
char* String)
|
||||
{
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
|
||||
.bRequest = ANDROID_Req_SendString,
|
||||
.wValue = 0,
|
||||
.wIndex = StringIndex,
|
||||
.wLength = (strlen(String) + 1),
|
||||
};
|
||||
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
return USB_Host_SendControlRequest(String);
|
||||
}
|
||||
|
||||
uint8_t Android_StartAccessoryMode(void)
|
||||
{
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
|
||||
.bRequest = ANDROID_Req_StartAccessoryMode,
|
||||
.wValue = 0,
|
||||
.wIndex = 0,
|
||||
.wLength = 0,
|
||||
};
|
||||
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
return USB_Host_SendControlRequest(NULL);
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for AndroidAccessoryCommands.c.
|
||||
*/
|
||||
|
||||
#ifndef _ANDROID_ACCESSORY_COMMANDS_H_
|
||||
#define _ANDROID_ACCESSORY_COMMANDS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
/* Enums: */
|
||||
enum Android_Requests_t
|
||||
{
|
||||
ANDROID_Req_GetAccessoryProtocol = 51,
|
||||
ANDROID_Req_SendString = 52,
|
||||
ANDROID_Req_StartAccessoryMode = 53,
|
||||
};
|
||||
|
||||
enum Android_Strings_t
|
||||
{
|
||||
ANDROID_STRING_Manufacturer = 0,
|
||||
ANDROID_STRING_Model = 1,
|
||||
ANDROID_STRING_Description = 2,
|
||||
ANDROID_STRING_Version = 3,
|
||||
ANDROID_STRING_URI = 4,
|
||||
ANDROID_STRING_Serial = 5,
|
||||
};
|
||||
|
||||
enum Android_Protocols_t
|
||||
{
|
||||
ANDROID_PROTOCOL_Accessory = 0x0001,
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t Android_GetAccessoryProtocol(uint16_t* const Protocol);
|
||||
uint8_t Android_SendString(const uint8_t StringIndex,
|
||||
char* String);
|
||||
uint8_t Android_StartAccessoryMode(void);
|
||||
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for AndroidAccessoryCommands.c.
|
||||
*/
|
||||
|
||||
#ifndef _ANDROID_ACCESSORY_COMMANDS_H_
|
||||
#define _ANDROID_ACCESSORY_COMMANDS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
/* Enums: */
|
||||
enum Android_Requests_t
|
||||
{
|
||||
ANDROID_Req_GetAccessoryProtocol = 51,
|
||||
ANDROID_Req_SendString = 52,
|
||||
ANDROID_Req_StartAccessoryMode = 53,
|
||||
};
|
||||
|
||||
enum Android_Strings_t
|
||||
{
|
||||
ANDROID_STRING_Manufacturer = 0,
|
||||
ANDROID_STRING_Model = 1,
|
||||
ANDROID_STRING_Description = 2,
|
||||
ANDROID_STRING_Version = 3,
|
||||
ANDROID_STRING_URI = 4,
|
||||
ANDROID_STRING_Serial = 5,
|
||||
};
|
||||
|
||||
enum Android_Protocols_t
|
||||
{
|
||||
ANDROID_PROTOCOL_Accessory = 0x0001,
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t Android_GetAccessoryProtocol(uint16_t* const Protocol);
|
||||
uint8_t Android_SendString(const uint8_t StringIndex,
|
||||
char* String);
|
||||
uint8_t Android_StartAccessoryMode(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,122 +1,122 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/*
|
||||
This is a header file which can be used to configure LUFA's
|
||||
compile time options, as an alternative to the compile time
|
||||
constants supplied through a makefile. To use this configuration
|
||||
header, copy this into your project's root directory and supply
|
||||
the USE_LUFA_CONFIG_HEADER token to the compiler so that it is
|
||||
defined in all compiled source files.
|
||||
|
||||
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 {Insert Value Here}
|
||||
// #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_CONFIGURATION {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 {Insert Value Here}
|
||||
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
|
||||
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
|
||||
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
|
||||
/* 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 {Insert Value Here}
|
||||
// #define USB_DEVICE_ONLY
|
||||
// #define USB_HOST_ONLY
|
||||
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
|
||||
// #define NO_SOF_EVENTS
|
||||
|
||||
/* USB Device Mode Driver Related Tokens: */
|
||||
// #define NO_INTERNAL_SERIAL
|
||||
// #define FIXED_CONTROL_ENDPOINT_SIZE {Insert Value Here}
|
||||
// #define FIXED_NUM_CONFIGURATION {Insert Value Here}
|
||||
// #define CONTROL_ONLY_DEVICE
|
||||
// #define NO_DEVICE_REMOTE_WAKEUP
|
||||
// #define NO_DEVICE_SELF_POWER
|
||||
|
||||
/* USB Host Mode Driver Related Tokens: */
|
||||
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
|
||||
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/*
|
||||
This is a header file which can be used to configure LUFA's
|
||||
compile time options, as an alternative to the compile time
|
||||
constants supplied through a makefile. To use this configuration
|
||||
header, copy this into your project's root directory and supply
|
||||
the USE_LUFA_CONFIG_HEADER token to the compiler so that it is
|
||||
defined in all compiled source files.
|
||||
|
||||
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 {Insert Value Here}
|
||||
// #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_CONFIGURATION {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 {Insert Value Here}
|
||||
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
|
||||
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
|
||||
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
|
||||
/* 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 {Insert Value Here}
|
||||
// #define USB_DEVICE_ONLY
|
||||
// #define USB_HOST_ONLY
|
||||
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
|
||||
// #define NO_SOF_EVENTS
|
||||
|
||||
/* USB Device Mode Driver Related Tokens: */
|
||||
// #define NO_INTERNAL_SERIAL
|
||||
// #define FIXED_CONTROL_ENDPOINT_SIZE {Insert Value Here}
|
||||
// #define FIXED_NUM_CONFIGURATION {Insert Value Here}
|
||||
// #define CONTROL_ONLY_DEVICE
|
||||
// #define NO_DEVICE_REMOTE_WAKEUP
|
||||
// #define NO_DEVICE_SELF_POWER
|
||||
|
||||
/* USB Host Mode Driver Related Tokens: */
|
||||
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
|
||||
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,486 +1,486 @@
|
||||
# Hey Emacs, this is a -*- makefile -*-
|
||||
#----------------------------------------------------------------------------
|
||||
# WinAVR Makefile Template written by Eric B. Weddington, J<>rg Wunsch, et al.
|
||||
# >> Modified for use with the LUFA project. <<
|
||||
#
|
||||
# Released to the Public Domain
|
||||
#
|
||||
# Additional material for this makefile was written by:
|
||||
# Peter Fleury
|
||||
# Tim Henigan
|
||||
# Colin O'Flynn
|
||||
# Reiner Patommel
|
||||
# Markus Pfaff
|
||||
# Sander Pool
|
||||
# Frederik Rouleau
|
||||
# Carlos Lamas
|
||||
# Dean Camera
|
||||
# Opendous Inc.
|
||||
# Denver Gingerich
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
# On command line:
|
||||
#
|
||||
# make all = Make software.
|
||||
#
|
||||
# make clean = Clean out built project files.
|
||||
#
|
||||
# make dfu = Download the hex file to the device, using dfu-programmer (must
|
||||
# have dfu-programmer installed).
|
||||
#
|
||||
# make flip = Download the hex file to the device, using Atmel FLIP (must
|
||||
# have Atmel FLIP installed).
|
||||
#
|
||||
# make doxygen = Generate DoxyGen documentation for the project (must have
|
||||
# DoxyGen installed)
|
||||
#
|
||||
# make filename.s = Just compile filename.c into the assembler code only.
|
||||
#
|
||||
# make filename.i = Create a preprocessed source file for use in submitting
|
||||
# bug reports to the GCC project.
|
||||
#
|
||||
# To rebuild project do "make clean" then "make all".
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
# MCU name
|
||||
MCU = ### INSERT NAME OF MICROCONTROLLER MODEL HERE ###
|
||||
|
||||
|
||||
# Targeted chip architecture (see library "Architectures" documentation)
|
||||
ARCH = UC3
|
||||
|
||||
|
||||
# Target board (see library "Board Types" documentation, NONE for projects not requiring
|
||||
# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
|
||||
# "Board" inside the application directory.
|
||||
BOARD = ### INSERT NAME OF BOARD HERE, OR NONE IF NO BOARD DRIVERS USED ###
|
||||
|
||||
|
||||
# Processor frequency.
|
||||
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||
# processor frequency in Hz. You can then use this symbol in your source code to
|
||||
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||
# automatically to create a 32-bit value in your source code.
|
||||
#
|
||||
# This should be the frequency the system core runs at, after the system clock
|
||||
# has been set up correctly and started.
|
||||
F_CPU = ### INSERT PRESCALED SYSTEM CLOCK SPEED HERE, IN HZ ###
|
||||
|
||||
|
||||
# USB controller master clock frequency.
|
||||
# This will define a symbol, F_USB, in all source code files equal to the
|
||||
# input clock frequency of the USB controller's clock generator in Hz.
|
||||
#
|
||||
# For the UC3 chips, this should be equal to 48MHz or 96MHz.
|
||||
F_USB = ### INSERT CLOCK TO USB MODULE HERE, IN HZ ###
|
||||
|
||||
|
||||
# Output format. (can be srec, ihex, binary)
|
||||
FORMAT = ihex
|
||||
|
||||
|
||||
# Target file name (without extension).
|
||||
TARGET = ### INSERT NAME OF MAIN FILENAME HERE, WITHOUT EXTENSION ###
|
||||
|
||||
|
||||
# Object files directory
|
||||
# To put object files in current directory, use a dot (.), do NOT make
|
||||
# this an empty or blank macro!
|
||||
OBJDIR = .
|
||||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ### INSERT PATH TO LUFA LIBRARY RELATIVE TO PROJECT DIRECTORY HERE ###
|
||||
|
||||
|
||||
# LUFA library compile-time options and predefined tokens (add '-D' before each token)
|
||||
LUFA_OPTS = ### INSERT LUFA COMPILE TIME TOKES HERE ###
|
||||
|
||||
|
||||
# Create the LUFA source path variables by including the LUFA root makefile
|
||||
include $(LUFA_PATH)/LUFA/makefile
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
$(LUFA_SRC_USB) \
|
||||
$(LUFA_SRC_USBCLASS)
|
||||
### INSERT ADDITIONAL PROJECT SOURCE FILENAMES OR LUFA MODULE NAMES HERE ###
|
||||
|
||||
|
||||
# List C++ source files here. (C dependencies are automatically generated.)
|
||||
CPPSRC =
|
||||
|
||||
|
||||
# List Assembler source files here.
|
||||
# Make them always end in a capital .S. Files ending in a lowercase .s
|
||||
# will not be considered source files but generated files (assembler
|
||||
# output from the compiler), and will be deleted upon "make clean"!
|
||||
# Even though the DOS/Win* filesystem matches both .s and .S the same,
|
||||
# it will preserve the spelling of the filenames, and gcc itself does
|
||||
# care about how the name is spelled on its command-line.
|
||||
ASRC =
|
||||
|
||||
|
||||
# Optimization level, can be [0, 1, 2, 3, s].
|
||||
# 0 = turn off optimization. s = optimize for size.
|
||||
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
|
||||
OPT = s
|
||||
|
||||
|
||||
# List any extra directories to look for include files here.
|
||||
# Each directory must be seperated by a space.
|
||||
# Use forward slashes for directory separators.
|
||||
# For a directory that has spaces, enclose it in quotes.
|
||||
EXTRAINCDIRS = $(LUFA_PATH)/
|
||||
|
||||
|
||||
# Compiler flag to set the C Standard level.
|
||||
# c89 = "ANSI" C
|
||||
# gnu89 = c89 plus GCC extensions
|
||||
# c99 = ISO C99 standard (not yet fully implemented)
|
||||
# gnu99 = c99 plus GCC extensions
|
||||
CSTANDARD = -std=gnu99
|
||||
|
||||
|
||||
# Place -D or -U options here for C sources
|
||||
CDEFS = -DF_CPU=$(F_CPU)UL
|
||||
CDEFS += -DF_USB=$(F_USB)UL
|
||||
CDEFS += -DBOARD=BOARD_$(BOARD)
|
||||
CDEFS += -DARCH=ARCH_$(ARCH)
|
||||
CDEFS += $(LUFA_OPTS)
|
||||
|
||||
|
||||
# Place -D or -U options here for ASM sources
|
||||
ADEFS = -DF_CPU=$(F_CPU)
|
||||
ADEFS += -DF_USB=$(F_USB)UL
|
||||
ADEFS += -DBOARD=BOARD_$(BOARD)
|
||||
ADEFS += -DARCH=ARCH_$(ARCH)
|
||||
ADEFS += $(LUFA_OPTS)
|
||||
|
||||
# Place -D or -U options here for C++ sources
|
||||
CPPDEFS = -DF_CPU=$(F_CPU)UL
|
||||
CPPDEFS += -DF_USB=$(F_USB)UL
|
||||
CPPDEFS += -DBOARD=BOARD_$(BOARD)
|
||||
CPPDEFS += -DARCH=ARCH_$(ARCH)
|
||||
CPPDEFS += $(LUFA_OPTS)
|
||||
|
||||
|
||||
# Debugging level.
|
||||
DEBUG = 3
|
||||
|
||||
|
||||
#---------------- Compiler Options C ----------------
|
||||
# -g*: generate debugging information
|
||||
# -O*: optimization level
|
||||
# -f...: tuning, see GCC manual and avr-libc documentation
|
||||
# -Wall...: warning level
|
||||
# -Wa,...: tell GCC to pass this to the assembler.
|
||||
# -adhlns...: create assembler listing
|
||||
CFLAGS = -g$(DEBUG)
|
||||
CFLAGS += $(CDEFS)
|
||||
CFLAGS += -O$(OPT)
|
||||
CFLAGS += -funsigned-char
|
||||
CFLAGS += -funsigned-bitfields
|
||||
CFLAGS += -ffunction-sections
|
||||
CFLAGS += -fno-strict-aliasing
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
CFLAGS += -masm-addr-pseudos
|
||||
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
||||
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
CFLAGS += $(CSTANDARD)
|
||||
|
||||
|
||||
#---------------- Compiler Options C++ ----------------
|
||||
# -g*: generate debugging information
|
||||
# -O*: optimization level
|
||||
# -f...: tuning, see GCC manual and avr-libc documentation
|
||||
# -Wall...: warning level
|
||||
# -Wa,...: tell GCC to pass this to the assembler.
|
||||
# -adhlns...: create assembler listing
|
||||
CPPFLAGS = -g$(DEBUG)
|
||||
CPPFLAGS += $(CPPDEFS)
|
||||
CPPFLAGS += -O$(OPT)
|
||||
CPPFLAGS += -funsigned-char
|
||||
CPPFLAGS += -funsigned-bitfields
|
||||
CPPFLAGS += -ffunction-sections
|
||||
CPPFLAGS += -fno-strict-aliasing
|
||||
CPPFLAGS += -fno-exceptions
|
||||
CPPFLAGS += -masm-addr-pseudos
|
||||
CPPFLAGS += -Wall
|
||||
CPPFLAGS += -Wundef
|
||||
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
|
||||
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
#CPPFLAGS += $(CSTANDARD)
|
||||
|
||||
|
||||
#---------------- Assembler Options ----------------
|
||||
# -Wa,...: tell GCC to pass this to the assembler.
|
||||
# -adhlns: create listing
|
||||
# -gstabs: have the assembler create line number information; note that
|
||||
# for use in COFF files, additional information about filenames
|
||||
# and function names needs to be present in the assembler source
|
||||
# files -- see avr-libc docs [FIXME: not yet described there]
|
||||
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
|
||||
# dump that will be displayed for a given single line of source input.
|
||||
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
|
||||
|
||||
|
||||
#---------------- Linker Options ----------------
|
||||
# -Wl,...: tell GCC to pass this to linker.
|
||||
# -Map: create map file
|
||||
# --cref: add cross reference to map file
|
||||
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
|
||||
LDFLAGS += -Wl,--gc-sections --rodata-writable
|
||||
LDFLAGS += -Wl,--direct-data
|
||||
#LDFLAGS += -T linker_script.x
|
||||
|
||||
|
||||
#============================================================================
|
||||
|
||||
|
||||
# Define programs and commands.
|
||||
SHELL = sh
|
||||
CC = avr32-gcc
|
||||
OBJCOPY = avr32-objcopy
|
||||
OBJDUMP = avr32-objdump
|
||||
SIZE = avr32-size
|
||||
AR = avr32-ar rcs
|
||||
NM = avr32-nm
|
||||
REMOVE = rm -f
|
||||
REMOVEDIR = rm -rf
|
||||
COPY = cp
|
||||
WINSHELL = cmd
|
||||
|
||||
|
||||
# Define Messages
|
||||
# English
|
||||
MSG_ERRORS_NONE = Errors: none
|
||||
MSG_BEGIN = -------- begin --------
|
||||
MSG_END = -------- end --------
|
||||
MSG_SIZE_BEFORE = Size before:
|
||||
MSG_SIZE_AFTER = Size after:
|
||||
MSG_COFF = Converting to AVR COFF:
|
||||
MSG_FLASH = Creating load file for Flash:
|
||||
MSG_EEPROM = Creating load file for EEPROM:
|
||||
MSG_EXTENDED_LISTING = Creating Extended Listing:
|
||||
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
||||
MSG_LINKING = Linking:
|
||||
MSG_COMPILING = Compiling C:
|
||||
MSG_COMPILING_CPP = Compiling C++:
|
||||
MSG_ASSEMBLING = Assembling:
|
||||
MSG_CLEANING = Cleaning project:
|
||||
MSG_CREATING_LIBRARY = Creating library:
|
||||
|
||||
|
||||
|
||||
|
||||
# Define all object files.
|
||||
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
|
||||
|
||||
# Define all listing files.
|
||||
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
|
||||
|
||||
|
||||
# Compiler flags to generate dependency files.
|
||||
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
|
||||
|
||||
|
||||
# Combine all necessary flags and optional flags.
|
||||
# Add target processor to flags.
|
||||
ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
|
||||
ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
|
||||
ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Default target.
|
||||
all: begin gccversion sizebefore build sizeafter end
|
||||
|
||||
# Change the build target to build a HEX file or a library.
|
||||
build: elf hex lss sym
|
||||
#build: lib
|
||||
|
||||
|
||||
elf: $(TARGET).elf
|
||||
hex: $(TARGET).hex
|
||||
lss: $(TARGET).lss
|
||||
sym: $(TARGET).sym
|
||||
LIBNAME=lib$(TARGET).a
|
||||
lib: $(LIBNAME)
|
||||
|
||||
|
||||
|
||||
# Eye candy.
|
||||
# AVR Studio 3.x does not check make's exit code but relies on
|
||||
# the following magic strings to be generated by the compile job.
|
||||
begin:
|
||||
@echo
|
||||
@echo $(MSG_BEGIN)
|
||||
|
||||
end:
|
||||
@echo $(MSG_END)
|
||||
@echo
|
||||
|
||||
|
||||
# Display size of file.
|
||||
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
|
||||
ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
|
||||
MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
|
||||
FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
|
||||
|
||||
|
||||
sizebefore:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
sizeafter:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
|
||||
|
||||
# Display compiler version information.
|
||||
gccversion :
|
||||
@$(CC) --version
|
||||
|
||||
|
||||
# Program the device.
|
||||
flip: $(TARGET).hex
|
||||
batchisp -hardware usb -device $(MCU) -operation erase f
|
||||
batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
|
||||
batchisp -hardware usb -device $(MCU) -operation start reset 0
|
||||
|
||||
dfu: $(TARGET).hex
|
||||
dfu-programmer $(MCU) erase
|
||||
dfu-programmer $(MCU) flash $(TARGET).hex
|
||||
dfu-programmer $(MCU) reset
|
||||
|
||||
|
||||
# Create final output files (.hex, .eep) from ELF output file.
|
||||
%.hex: %.elf
|
||||
@echo
|
||||
@echo $(MSG_FLASH) $@
|
||||
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
%.lss: %.elf
|
||||
@echo
|
||||
@echo $(MSG_EXTENDED_LISTING) $@
|
||||
$(OBJDUMP) -h -S -z $< > $@
|
||||
|
||||
# Create a symbol table from ELF output file.
|
||||
%.sym: %.elf
|
||||
@echo
|
||||
@echo $(MSG_SYMBOL_TABLE) $@
|
||||
$(NM) -n $< > $@
|
||||
|
||||
|
||||
|
||||
# Create library from object files.
|
||||
.SECONDARY : $(TARGET).a
|
||||
.PRECIOUS : $(OBJ)
|
||||
%.a: $(OBJ)
|
||||
@echo
|
||||
@echo $(MSG_CREATING_LIBRARY) $@
|
||||
$(AR) $@ $(OBJ)
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
.SECONDARY : $(TARGET).elf
|
||||
.PRECIOUS : $(OBJ)
|
||||
%.elf: $(OBJ)
|
||||
@echo
|
||||
@echo $(MSG_LINKING) $@
|
||||
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
$(OBJDIR)/%.o : %.c
|
||||
@echo
|
||||
@echo $(MSG_COMPILING) $<
|
||||
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Compile: create object files from C++ source files.
|
||||
$(OBJDIR)/%.o : %.cpp
|
||||
@echo
|
||||
@echo $(MSG_COMPILING_CPP) $<
|
||||
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Compile: create assembler files from C source files.
|
||||
%.s : %.c
|
||||
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Compile: create assembler files from C++ source files.
|
||||
%.s : %.cpp
|
||||
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Assemble: create object files from assembler source files.
|
||||
$(OBJDIR)/%.o : %.S
|
||||
@echo
|
||||
@echo $(MSG_ASSEMBLING) $<
|
||||
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Create preprocessed source for use in sending a bug report.
|
||||
%.i : %.c
|
||||
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
clean: begin clean_list end
|
||||
|
||||
clean_list :
|
||||
@echo
|
||||
@echo $(MSG_CLEANING)
|
||||
$(REMOVE) $(TARGET).hex
|
||||
$(REMOVE) $(TARGET).cof
|
||||
$(REMOVE) $(TARGET).elf
|
||||
$(REMOVE) $(TARGET).map
|
||||
$(REMOVE) $(TARGET).sym
|
||||
$(REMOVE) $(TARGET).lss
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
|
||||
$(REMOVE) $(SRC:.c=.s)
|
||||
$(REMOVE) $(SRC:.c=.d)
|
||||
$(REMOVE) $(SRC:.c=.i)
|
||||
$(REMOVEDIR) .dep
|
||||
|
||||
doxygen:
|
||||
@echo Generating Project Documentation...
|
||||
@doxygen Doxygen.conf
|
||||
@echo Documentation Generation Complete.
|
||||
|
||||
clean_doxygen:
|
||||
rm -rf Documentation
|
||||
|
||||
checksource:
|
||||
@for f in $(SRC) $(CPPSRC) $(ASRC); do \
|
||||
if [ -f $$f ]; then \
|
||||
echo "Found Source File: $$f" ; \
|
||||
else \
|
||||
echo "Source File Not Found: $$f" ; \
|
||||
fi; done
|
||||
|
||||
|
||||
# Create object files directory
|
||||
$(shell mkdir $(OBJDIR) 2>/dev/null)
|
||||
|
||||
|
||||
# Include the dependency files.
|
||||
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
|
||||
# Listing of phony targets.
|
||||
.PHONY : all begin finish end sizebefore sizeafter gccversion \
|
||||
build elf hex lss sym doxygen clean clean_list clean_doxygen \
|
||||
dfu flip checksource
|
||||
|
||||
# Hey Emacs, this is a -*- makefile -*-
|
||||
#----------------------------------------------------------------------------
|
||||
# WinAVR Makefile Template written by Eric B. Weddington, J<>rg Wunsch, et al.
|
||||
# >> Modified for use with the LUFA project. <<
|
||||
#
|
||||
# Released to the Public Domain
|
||||
#
|
||||
# Additional material for this makefile was written by:
|
||||
# Peter Fleury
|
||||
# Tim Henigan
|
||||
# Colin O'Flynn
|
||||
# Reiner Patommel
|
||||
# Markus Pfaff
|
||||
# Sander Pool
|
||||
# Frederik Rouleau
|
||||
# Carlos Lamas
|
||||
# Dean Camera
|
||||
# Opendous Inc.
|
||||
# Denver Gingerich
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
# On command line:
|
||||
#
|
||||
# make all = Make software.
|
||||
#
|
||||
# make clean = Clean out built project files.
|
||||
#
|
||||
# make dfu = Download the hex file to the device, using dfu-programmer (must
|
||||
# have dfu-programmer installed).
|
||||
#
|
||||
# make flip = Download the hex file to the device, using Atmel FLIP (must
|
||||
# have Atmel FLIP installed).
|
||||
#
|
||||
# make doxygen = Generate DoxyGen documentation for the project (must have
|
||||
# DoxyGen installed)
|
||||
#
|
||||
# make filename.s = Just compile filename.c into the assembler code only.
|
||||
#
|
||||
# make filename.i = Create a preprocessed source file for use in submitting
|
||||
# bug reports to the GCC project.
|
||||
#
|
||||
# To rebuild project do "make clean" then "make all".
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
# MCU name
|
||||
MCU = ### INSERT NAME OF MICROCONTROLLER MODEL HERE ###
|
||||
|
||||
|
||||
# Targeted chip architecture (see library "Architectures" documentation)
|
||||
ARCH = UC3
|
||||
|
||||
|
||||
# Target board (see library "Board Types" documentation, NONE for projects not requiring
|
||||
# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
|
||||
# "Board" inside the application directory.
|
||||
BOARD = ### INSERT NAME OF BOARD HERE, OR NONE IF NO BOARD DRIVERS USED ###
|
||||
|
||||
|
||||
# Processor frequency.
|
||||
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||
# processor frequency in Hz. You can then use this symbol in your source code to
|
||||
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||
# automatically to create a 32-bit value in your source code.
|
||||
#
|
||||
# This should be the frequency the system core runs at, after the system clock
|
||||
# has been set up correctly and started.
|
||||
F_CPU = ### INSERT PRESCALED SYSTEM CLOCK SPEED HERE, IN HZ ###
|
||||
|
||||
|
||||
# USB controller master clock frequency.
|
||||
# This will define a symbol, F_USB, in all source code files equal to the
|
||||
# input clock frequency of the USB controller's clock generator in Hz.
|
||||
#
|
||||
# For the UC3 chips, this should be equal to 48MHz or 96MHz.
|
||||
F_USB = ### INSERT CLOCK TO USB MODULE HERE, IN HZ ###
|
||||
|
||||
|
||||
# Output format. (can be srec, ihex, binary)
|
||||
FORMAT = ihex
|
||||
|
||||
|
||||
# Target file name (without extension).
|
||||
TARGET = ### INSERT NAME OF MAIN FILENAME HERE, WITHOUT EXTENSION ###
|
||||
|
||||
|
||||
# Object files directory
|
||||
# To put object files in current directory, use a dot (.), do NOT make
|
||||
# this an empty or blank macro!
|
||||
OBJDIR = .
|
||||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ### INSERT PATH TO LUFA LIBRARY RELATIVE TO PROJECT DIRECTORY HERE ###
|
||||
|
||||
|
||||
# LUFA library compile-time options and predefined tokens (add '-D' before each token)
|
||||
LUFA_OPTS = ### INSERT LUFA COMPILE TIME TOKES HERE ###
|
||||
|
||||
|
||||
# Create the LUFA source path variables by including the LUFA root makefile
|
||||
include $(LUFA_PATH)/LUFA/makefile
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
$(LUFA_SRC_USB) \
|
||||
$(LUFA_SRC_USBCLASS)
|
||||
### INSERT ADDITIONAL PROJECT SOURCE FILENAMES OR LUFA MODULE NAMES HERE ###
|
||||
|
||||
|
||||
# List C++ source files here. (C dependencies are automatically generated.)
|
||||
CPPSRC =
|
||||
|
||||
|
||||
# List Assembler source files here.
|
||||
# Make them always end in a capital .S. Files ending in a lowercase .s
|
||||
# will not be considered source files but generated files (assembler
|
||||
# output from the compiler), and will be deleted upon "make clean"!
|
||||
# Even though the DOS/Win* filesystem matches both .s and .S the same,
|
||||
# it will preserve the spelling of the filenames, and gcc itself does
|
||||
# care about how the name is spelled on its command-line.
|
||||
ASRC =
|
||||
|
||||
|
||||
# Optimization level, can be [0, 1, 2, 3, s].
|
||||
# 0 = turn off optimization. s = optimize for size.
|
||||
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
|
||||
OPT = s
|
||||
|
||||
|
||||
# List any extra directories to look for include files here.
|
||||
# Each directory must be seperated by a space.
|
||||
# Use forward slashes for directory separators.
|
||||
# For a directory that has spaces, enclose it in quotes.
|
||||
EXTRAINCDIRS = $(LUFA_PATH)/
|
||||
|
||||
|
||||
# Compiler flag to set the C Standard level.
|
||||
# c89 = "ANSI" C
|
||||
# gnu89 = c89 plus GCC extensions
|
||||
# c99 = ISO C99 standard (not yet fully implemented)
|
||||
# gnu99 = c99 plus GCC extensions
|
||||
CSTANDARD = -std=gnu99
|
||||
|
||||
|
||||
# Place -D or -U options here for C sources
|
||||
CDEFS = -DF_CPU=$(F_CPU)UL
|
||||
CDEFS += -DF_USB=$(F_USB)UL
|
||||
CDEFS += -DBOARD=BOARD_$(BOARD)
|
||||
CDEFS += -DARCH=ARCH_$(ARCH)
|
||||
CDEFS += $(LUFA_OPTS)
|
||||
|
||||
|
||||
# Place -D or -U options here for ASM sources
|
||||
ADEFS = -DF_CPU=$(F_CPU)
|
||||
ADEFS += -DF_USB=$(F_USB)UL
|
||||
ADEFS += -DBOARD=BOARD_$(BOARD)
|
||||
ADEFS += -DARCH=ARCH_$(ARCH)
|
||||
ADEFS += $(LUFA_OPTS)
|
||||
|
||||
# Place -D or -U options here for C++ sources
|
||||
CPPDEFS = -DF_CPU=$(F_CPU)UL
|
||||
CPPDEFS += -DF_USB=$(F_USB)UL
|
||||
CPPDEFS += -DBOARD=BOARD_$(BOARD)
|
||||
CPPDEFS += -DARCH=ARCH_$(ARCH)
|
||||
CPPDEFS += $(LUFA_OPTS)
|
||||
|
||||
|
||||
# Debugging level.
|
||||
DEBUG = 3
|
||||
|
||||
|
||||
#---------------- Compiler Options C ----------------
|
||||
# -g*: generate debugging information
|
||||
# -O*: optimization level
|
||||
# -f...: tuning, see GCC manual and avr-libc documentation
|
||||
# -Wall...: warning level
|
||||
# -Wa,...: tell GCC to pass this to the assembler.
|
||||
# -adhlns...: create assembler listing
|
||||
CFLAGS = -g$(DEBUG)
|
||||
CFLAGS += $(CDEFS)
|
||||
CFLAGS += -O$(OPT)
|
||||
CFLAGS += -funsigned-char
|
||||
CFLAGS += -funsigned-bitfields
|
||||
CFLAGS += -ffunction-sections
|
||||
CFLAGS += -fno-strict-aliasing
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
CFLAGS += -masm-addr-pseudos
|
||||
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
||||
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
CFLAGS += $(CSTANDARD)
|
||||
|
||||
|
||||
#---------------- Compiler Options C++ ----------------
|
||||
# -g*: generate debugging information
|
||||
# -O*: optimization level
|
||||
# -f...: tuning, see GCC manual and avr-libc documentation
|
||||
# -Wall...: warning level
|
||||
# -Wa,...: tell GCC to pass this to the assembler.
|
||||
# -adhlns...: create assembler listing
|
||||
CPPFLAGS = -g$(DEBUG)
|
||||
CPPFLAGS += $(CPPDEFS)
|
||||
CPPFLAGS += -O$(OPT)
|
||||
CPPFLAGS += -funsigned-char
|
||||
CPPFLAGS += -funsigned-bitfields
|
||||
CPPFLAGS += -ffunction-sections
|
||||
CPPFLAGS += -fno-strict-aliasing
|
||||
CPPFLAGS += -fno-exceptions
|
||||
CPPFLAGS += -masm-addr-pseudos
|
||||
CPPFLAGS += -Wall
|
||||
CPPFLAGS += -Wundef
|
||||
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
|
||||
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
#CPPFLAGS += $(CSTANDARD)
|
||||
|
||||
|
||||
#---------------- Assembler Options ----------------
|
||||
# -Wa,...: tell GCC to pass this to the assembler.
|
||||
# -adhlns: create listing
|
||||
# -gstabs: have the assembler create line number information; note that
|
||||
# for use in COFF files, additional information about filenames
|
||||
# and function names needs to be present in the assembler source
|
||||
# files -- see avr-libc docs [FIXME: not yet described there]
|
||||
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
|
||||
# dump that will be displayed for a given single line of source input.
|
||||
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
|
||||
|
||||
|
||||
#---------------- Linker Options ----------------
|
||||
# -Wl,...: tell GCC to pass this to linker.
|
||||
# -Map: create map file
|
||||
# --cref: add cross reference to map file
|
||||
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
|
||||
LDFLAGS += -Wl,--gc-sections --rodata-writable
|
||||
LDFLAGS += -Wl,--direct-data
|
||||
#LDFLAGS += -T linker_script.x
|
||||
|
||||
|
||||
#============================================================================
|
||||
|
||||
|
||||
# Define programs and commands.
|
||||
SHELL = sh
|
||||
CC = avr32-gcc
|
||||
OBJCOPY = avr32-objcopy
|
||||
OBJDUMP = avr32-objdump
|
||||
SIZE = avr32-size
|
||||
AR = avr32-ar rcs
|
||||
NM = avr32-nm
|
||||
REMOVE = rm -f
|
||||
REMOVEDIR = rm -rf
|
||||
COPY = cp
|
||||
WINSHELL = cmd
|
||||
|
||||
|
||||
# Define Messages
|
||||
# English
|
||||
MSG_ERRORS_NONE = Errors: none
|
||||
MSG_BEGIN = -------- begin --------
|
||||
MSG_END = -------- end --------
|
||||
MSG_SIZE_BEFORE = Size before:
|
||||
MSG_SIZE_AFTER = Size after:
|
||||
MSG_COFF = Converting to AVR COFF:
|
||||
MSG_FLASH = Creating load file for Flash:
|
||||
MSG_EEPROM = Creating load file for EEPROM:
|
||||
MSG_EXTENDED_LISTING = Creating Extended Listing:
|
||||
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
||||
MSG_LINKING = Linking:
|
||||
MSG_COMPILING = Compiling C:
|
||||
MSG_COMPILING_CPP = Compiling C++:
|
||||
MSG_ASSEMBLING = Assembling:
|
||||
MSG_CLEANING = Cleaning project:
|
||||
MSG_CREATING_LIBRARY = Creating library:
|
||||
|
||||
|
||||
|
||||
|
||||
# Define all object files.
|
||||
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
|
||||
|
||||
# Define all listing files.
|
||||
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
|
||||
|
||||
|
||||
# Compiler flags to generate dependency files.
|
||||
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
|
||||
|
||||
|
||||
# Combine all necessary flags and optional flags.
|
||||
# Add target processor to flags.
|
||||
ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
|
||||
ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
|
||||
ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Default target.
|
||||
all: begin gccversion sizebefore build sizeafter end
|
||||
|
||||
# Change the build target to build a HEX file or a library.
|
||||
build: elf hex lss sym
|
||||
#build: lib
|
||||
|
||||
|
||||
elf: $(TARGET).elf
|
||||
hex: $(TARGET).hex
|
||||
lss: $(TARGET).lss
|
||||
sym: $(TARGET).sym
|
||||
LIBNAME=lib$(TARGET).a
|
||||
lib: $(LIBNAME)
|
||||
|
||||
|
||||
|
||||
# Eye candy.
|
||||
# AVR Studio 3.x does not check make's exit code but relies on
|
||||
# the following magic strings to be generated by the compile job.
|
||||
begin:
|
||||
@echo
|
||||
@echo $(MSG_BEGIN)
|
||||
|
||||
end:
|
||||
@echo $(MSG_END)
|
||||
@echo
|
||||
|
||||
|
||||
# Display size of file.
|
||||
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
|
||||
ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
|
||||
MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
|
||||
FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
|
||||
|
||||
|
||||
sizebefore:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
sizeafter:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
|
||||
|
||||
# Display compiler version information.
|
||||
gccversion :
|
||||
@$(CC) --version
|
||||
|
||||
|
||||
# Program the device.
|
||||
flip: $(TARGET).hex
|
||||
batchisp -hardware usb -device $(MCU) -operation erase f
|
||||
batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
|
||||
batchisp -hardware usb -device $(MCU) -operation start reset 0
|
||||
|
||||
dfu: $(TARGET).hex
|
||||
dfu-programmer $(MCU) erase
|
||||
dfu-programmer $(MCU) flash $(TARGET).hex
|
||||
dfu-programmer $(MCU) reset
|
||||
|
||||
|
||||
# Create final output files (.hex, .eep) from ELF output file.
|
||||
%.hex: %.elf
|
||||
@echo
|
||||
@echo $(MSG_FLASH) $@
|
||||
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
%.lss: %.elf
|
||||
@echo
|
||||
@echo $(MSG_EXTENDED_LISTING) $@
|
||||
$(OBJDUMP) -h -S -z $< > $@
|
||||
|
||||
# Create a symbol table from ELF output file.
|
||||
%.sym: %.elf
|
||||
@echo
|
||||
@echo $(MSG_SYMBOL_TABLE) $@
|
||||
$(NM) -n $< > $@
|
||||
|
||||
|
||||
|
||||
# Create library from object files.
|
||||
.SECONDARY : $(TARGET).a
|
||||
.PRECIOUS : $(OBJ)
|
||||
%.a: $(OBJ)
|
||||
@echo
|
||||
@echo $(MSG_CREATING_LIBRARY) $@
|
||||
$(AR) $@ $(OBJ)
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
.SECONDARY : $(TARGET).elf
|
||||
.PRECIOUS : $(OBJ)
|
||||
%.elf: $(OBJ)
|
||||
@echo
|
||||
@echo $(MSG_LINKING) $@
|
||||
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
$(OBJDIR)/%.o : %.c
|
||||
@echo
|
||||
@echo $(MSG_COMPILING) $<
|
||||
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Compile: create object files from C++ source files.
|
||||
$(OBJDIR)/%.o : %.cpp
|
||||
@echo
|
||||
@echo $(MSG_COMPILING_CPP) $<
|
||||
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Compile: create assembler files from C source files.
|
||||
%.s : %.c
|
||||
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Compile: create assembler files from C++ source files.
|
||||
%.s : %.cpp
|
||||
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Assemble: create object files from assembler source files.
|
||||
$(OBJDIR)/%.o : %.S
|
||||
@echo
|
||||
@echo $(MSG_ASSEMBLING) $<
|
||||
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Create preprocessed source for use in sending a bug report.
|
||||
%.i : %.c
|
||||
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
clean: begin clean_list end
|
||||
|
||||
clean_list :
|
||||
@echo
|
||||
@echo $(MSG_CLEANING)
|
||||
$(REMOVE) $(TARGET).hex
|
||||
$(REMOVE) $(TARGET).cof
|
||||
$(REMOVE) $(TARGET).elf
|
||||
$(REMOVE) $(TARGET).map
|
||||
$(REMOVE) $(TARGET).sym
|
||||
$(REMOVE) $(TARGET).lss
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
|
||||
$(REMOVE) $(SRC:.c=.s)
|
||||
$(REMOVE) $(SRC:.c=.d)
|
||||
$(REMOVE) $(SRC:.c=.i)
|
||||
$(REMOVEDIR) .dep
|
||||
|
||||
doxygen:
|
||||
@echo Generating Project Documentation...
|
||||
@doxygen Doxygen.conf
|
||||
@echo Documentation Generation Complete.
|
||||
|
||||
clean_doxygen:
|
||||
rm -rf Documentation
|
||||
|
||||
checksource:
|
||||
@for f in $(SRC) $(CPPSRC) $(ASRC); do \
|
||||
if [ -f $$f ]; then \
|
||||
echo "Found Source File: $$f" ; \
|
||||
else \
|
||||
echo "Source File Not Found: $$f" ; \
|
||||
fi; done
|
||||
|
||||
|
||||
# Create object files directory
|
||||
$(shell mkdir $(OBJDIR) 2>/dev/null)
|
||||
|
||||
|
||||
# Include the dependency files.
|
||||
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
|
||||
# Listing of phony targets.
|
||||
.PHONY : all begin finish end sizebefore sizeafter gccversion \
|
||||
build elf hex lss sym doxygen clean clean_list clean_doxygen \
|
||||
dfu flip checksource
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,84 +1,84 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Supported library architecture defines.
|
||||
*
|
||||
* \copydetails Group_Architectures
|
||||
*
|
||||
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
|
||||
* functionality.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_Architectures Hardware Architectures
|
||||
* \brief Supported library architecture defines.
|
||||
*
|
||||
* Architecture macros for selecting the desired target microcontroller architecture. One of these values should be
|
||||
* defined as the value of \c ARCH in the user project makefile via the \c -D compiler switch to GCC, to select the
|
||||
* target architecture.
|
||||
*
|
||||
* The selected architecture should remain consistent with the makefile \c ARCH value, which is used to select the
|
||||
* underlying driver source files for each architecture.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LUFA_ARCHITECTURES_H__
|
||||
#define __LUFA_ARCHITECTURES_H__
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_COMMON_H)
|
||||
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Selects the Atmel 8-bit AVR (AT90USB* and ATMEGA*U* chips) architecture. */
|
||||
#define ARCH_AVR8 0
|
||||
|
||||
/** Selects the Atmel 32-bit UC3 AVR (AT32UC3* chips) architecture. */
|
||||
#define ARCH_UC3 1
|
||||
|
||||
/** Selects the Atmel XMEGA AVR (ATXMEGA*U chips) architecture. */
|
||||
#define ARCH_XMEGA 2
|
||||
|
||||
#if !defined(__DOXYGEN__)
|
||||
#define ARCH_ ARCH_AVR8
|
||||
|
||||
#if !defined(ARCH)
|
||||
#define ARCH ARCH_AVR8
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Supported library architecture defines.
|
||||
*
|
||||
* \copydetails Group_Architectures
|
||||
*
|
||||
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
|
||||
* functionality.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_Architectures Hardware Architectures
|
||||
* \brief Supported library architecture defines.
|
||||
*
|
||||
* Architecture macros for selecting the desired target microcontroller architecture. One of these values should be
|
||||
* defined as the value of \c ARCH in the user project makefile via the \c -D compiler switch to GCC, to select the
|
||||
* target architecture.
|
||||
*
|
||||
* The selected architecture should remain consistent with the makefile \c ARCH value, which is used to select the
|
||||
* underlying driver source files for each architecture.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LUFA_ARCHITECTURES_H__
|
||||
#define __LUFA_ARCHITECTURES_H__
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_COMMON_H)
|
||||
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Selects the Atmel 8-bit AVR (AT90USB* and ATMEGA*U* chips) architecture. */
|
||||
#define ARCH_AVR8 0
|
||||
|
||||
/** Selects the Atmel 32-bit UC3 AVR (AT32UC3* chips) architecture. */
|
||||
#define ARCH_UC3 1
|
||||
|
||||
/** Selects the Atmel XMEGA AVR (ATXMEGA*U chips) architecture. */
|
||||
#define ARCH_XMEGA 2
|
||||
|
||||
#if !defined(__DOXYGEN__)
|
||||
#define ARCH_ ARCH_AVR8
|
||||
|
||||
#if !defined(ARCH)
|
||||
#define ARCH ARCH_AVR8
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,98 +1,98 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Compiler specific macros for code optimization and correctness.
|
||||
*
|
||||
* \copydetails Group_CompilerSpecific
|
||||
*
|
||||
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
|
||||
* functionality.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_CompilerSpecific Compiler Specific Macros
|
||||
* \brief Compiler specific macros for code optimization and correctness.
|
||||
*
|
||||
* Compiler specific macros to expose certain compiler features which may increase the level of code optimization
|
||||
* for a specific compiler, or correct certain issues that may be present such as memory barriers for use in conjunction
|
||||
* with atomic variable access.
|
||||
*
|
||||
* Where possible, on alternative compilers, these macros will either have no effect, or default to returning a sane value
|
||||
* so that they can be used in existing code without the need for extra compiler checks in the user application code.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LUFA_COMPILERSPEC_H__
|
||||
#define __LUFA_COMPILERSPEC_H__
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_COMMON_H)
|
||||
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
#if defined(__GNUC__) || defined(__DOXYGEN__)
|
||||
/** Forces GCC to use pointer indirection (via the device's pointer register pairs) when accessing the given
|
||||
* struct pointer. In some cases GCC will emit non-optimal assembly code when accessing a structure through
|
||||
* a pointer, resulting in a larger binary. When this macro is used on a (non \c const) structure pointer before
|
||||
* use, it will force GCC to use pointer indirection on the elements rather than direct store and load
|
||||
* instructions.
|
||||
*
|
||||
* \param[in, out] StructPtr Pointer to a structure which is to be forced into indirect access mode.
|
||||
*/
|
||||
#define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr))
|
||||
|
||||
/** Forces GCC to create a memory barrier, ensuring that memory accesses are not reordered past the barrier point.
|
||||
* This can be used before ordering-critical operations, to ensure that the compiler does not re-order the resulting
|
||||
* assembly output in an unexpected manner on sections of code that are ordering-specific.
|
||||
*/
|
||||
#define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory");
|
||||
|
||||
/** Evaluates to boolean true if the specified value can be determined at compile time to be a constant value
|
||||
* when compiling under GCC.
|
||||
*
|
||||
* \param[in] x Value to check compile time constantness of.
|
||||
*
|
||||
* \return Boolean true if the given value is known to be a compile time constant.
|
||||
*/
|
||||
#define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x)
|
||||
#else
|
||||
#define GCC_FORCE_POINTER_ACCESS(StructPtr)
|
||||
#define GCC_MEMORY_BARRIER()
|
||||
#define GCC_IS_COMPILE_CONST(x) 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Compiler specific macros for code optimization and correctness.
|
||||
*
|
||||
* \copydetails Group_CompilerSpecific
|
||||
*
|
||||
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
|
||||
* functionality.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_CompilerSpecific Compiler Specific Macros
|
||||
* \brief Compiler specific macros for code optimization and correctness.
|
||||
*
|
||||
* Compiler specific macros to expose certain compiler features which may increase the level of code optimization
|
||||
* for a specific compiler, or correct certain issues that may be present such as memory barriers for use in conjunction
|
||||
* with atomic variable access.
|
||||
*
|
||||
* Where possible, on alternative compilers, these macros will either have no effect, or default to returning a sane value
|
||||
* so that they can be used in existing code without the need for extra compiler checks in the user application code.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LUFA_COMPILERSPEC_H__
|
||||
#define __LUFA_COMPILERSPEC_H__
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_COMMON_H)
|
||||
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
#if defined(__GNUC__) || defined(__DOXYGEN__)
|
||||
/** Forces GCC to use pointer indirection (via the device's pointer register pairs) when accessing the given
|
||||
* struct pointer. In some cases GCC will emit non-optimal assembly code when accessing a structure through
|
||||
* a pointer, resulting in a larger binary. When this macro is used on a (non \c const) structure pointer before
|
||||
* use, it will force GCC to use pointer indirection on the elements rather than direct store and load
|
||||
* instructions.
|
||||
*
|
||||
* \param[in, out] StructPtr Pointer to a structure which is to be forced into indirect access mode.
|
||||
*/
|
||||
#define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr))
|
||||
|
||||
/** Forces GCC to create a memory barrier, ensuring that memory accesses are not reordered past the barrier point.
|
||||
* This can be used before ordering-critical operations, to ensure that the compiler does not re-order the resulting
|
||||
* assembly output in an unexpected manner on sections of code that are ordering-specific.
|
||||
*/
|
||||
#define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory");
|
||||
|
||||
/** Evaluates to boolean true if the specified value can be determined at compile time to be a constant value
|
||||
* when compiling under GCC.
|
||||
*
|
||||
* \param[in] x Value to check compile time constantness of.
|
||||
*
|
||||
* \return Boolean true if the given value is known to be a compile time constant.
|
||||
*/
|
||||
#define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x)
|
||||
#else
|
||||
#define GCC_FORCE_POINTER_ACCESS(StructPtr)
|
||||
#define GCC_MEMORY_BARRIER()
|
||||
#define GCC_IS_COMPILE_CONST(x) 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,476 +1,476 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Endianness and Byte Ordering macros and functions.
|
||||
*
|
||||
* \copydetails Group_Endianness
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Endianness
|
||||
* \defgroup Group_ByteSwapping Byte Reordering
|
||||
* \brief Macros and functions for forced byte reordering.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Endianness
|
||||
* \defgroup Group_EndianConversion Endianness Conversion
|
||||
* \brief Macros and functions for automatic endianness conversion.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_Endianness Endianness and Byte Ordering
|
||||
* \brief Convenience macros and functions relating to byte (re-)ordering
|
||||
*
|
||||
* Common library convenience macros and functions relating to byte (re-)ordering.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LUFA_ENDIANNESS_H__
|
||||
#define __LUFA_ENDIANNESS_H__
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_COMMON_H)
|
||||
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
|
||||
#endif
|
||||
|
||||
#if !(defined(ARCH_BIG_ENDIAN) || defined(ARCH_LITTLE_ENDIAN))
|
||||
#error ARCH_BIG_ENDIAN or ARCH_LITTLE_ENDIAN not set for the specified architecture.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Swaps the byte ordering of a 16-bit value at compile-time. Do not use this macro for swapping byte orderings
|
||||
* of dynamic values computed at runtime, use \ref SwapEndian_16() instead. The result of this macro can be used
|
||||
* inside struct or other variable initializers outside of a function, something that is not possible with the
|
||||
* inline function variant.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in] x 16-bit value whose byte ordering is to be swapped.
|
||||
*
|
||||
* \return Input value with the byte ordering reversed.
|
||||
*/
|
||||
#define SWAPENDIAN_16(x) (uint16_t)((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
|
||||
|
||||
/** Swaps the byte ordering of a 32-bit value at compile-time. Do not use this macro for swapping byte orderings
|
||||
* of dynamic values computed at runtime- use \ref SwapEndian_32() instead. The result of this macro can be used
|
||||
* inside struct or other variable initializers outside of a function, something that is not possible with the
|
||||
* inline function variant.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in] x 32-bit value whose byte ordering is to be swapped.
|
||||
*
|
||||
* \return Input value with the byte ordering reversed.
|
||||
*/
|
||||
#define SWAPENDIAN_32(x) (uint32_t)((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \
|
||||
(((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))
|
||||
|
||||
#if defined(ARCH_BIG_ENDIAN) && !defined(le16_to_cpu)
|
||||
#define le16_to_cpu(x) SwapEndian_16(x)
|
||||
#define le32_to_cpu(x) SwapEndian_32(x)
|
||||
#define be16_to_cpu(x) x
|
||||
#define be32_to_cpu(x) x
|
||||
#define cpu_to_le16(x) SwapEndian_16(x)
|
||||
#define cpu_to_le32(x) SwapEndian_32(x)
|
||||
#define cpu_to_be16(x) x
|
||||
#define cpu_to_be32(x) x
|
||||
#define LE16_TO_CPU(x) SWAPENDIAN_16(x)
|
||||
#define LE32_TO_CPU(x) SWAPENDIAN_32(x)
|
||||
#define BE16_TO_CPU(x) x
|
||||
#define BE32_TO_CPU(x) x
|
||||
#define CPU_TO_LE16(x) SWAPENDIAN_16(x)
|
||||
#define CPU_TO_LE32(x) SWAPENDIAN_32(x)
|
||||
#define CPU_TO_BE16(x) x
|
||||
#define CPU_TO_BE32(x) x
|
||||
#elif !defined(le16_to_cpu)
|
||||
/** \name Run-time endianness conversion */
|
||||
//@{
|
||||
|
||||
/** Performs a conversion between a Little Endian encoded 16-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref LE16_TO_CPU instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define le16_to_cpu(x) x
|
||||
|
||||
/** Performs a conversion between a Little Endian encoded 32-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref LE32_TO_CPU instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define le32_to_cpu(x) x
|
||||
|
||||
/** Performs a conversion between a Big Endian encoded 16-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref BE16_TO_CPU instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define be16_to_cpu(x) SwapEndian_16(x)
|
||||
|
||||
/** Performs a conversion between a Big Endian encoded 32-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref BE32_TO_CPU instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define be32_to_cpu(x) SwapEndian_32(x)
|
||||
|
||||
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
|
||||
* is in Little Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref CPU_TO_LE16 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define cpu_to_le16(x) x
|
||||
|
||||
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
|
||||
* is in Little Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref CPU_TO_LE32 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define cpu_to_le32(x) x
|
||||
|
||||
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
|
||||
* is in Big Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref CPU_TO_BE16 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define cpu_to_be16(x) SwapEndian_16(x)
|
||||
|
||||
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
|
||||
* is in Big Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref CPU_TO_BE32 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define cpu_to_be32(x) SwapEndian_32(x)
|
||||
|
||||
//@}
|
||||
|
||||
/** \name Compile-time endianness conversion */
|
||||
//@{
|
||||
|
||||
/** Performs a conversion between a Little Endian encoded 16-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run time endianness
|
||||
* conversion, use \ref le16_to_cpu instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define LE16_TO_CPU(x) x
|
||||
|
||||
/** Performs a conversion between a Little Endian encoded 32-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run time endianness
|
||||
* conversion, use \ref le32_to_cpu instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define LE32_TO_CPU(x) x
|
||||
|
||||
/** Performs a conversion between a Big Endian encoded 16-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref be16_to_cpu instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define BE16_TO_CPU(x) SWAPENDIAN_16(x)
|
||||
|
||||
/** Performs a conversion between a Big Endian encoded 32-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref be32_to_cpu instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define BE32_TO_CPU(x) SWAPENDIAN_32(x)
|
||||
|
||||
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
|
||||
* is in Little Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref cpu_to_le16 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define CPU_TO_LE16(x) x
|
||||
|
||||
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
|
||||
* is in Little Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref cpu_to_le32 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define CPU_TO_LE32(x) x
|
||||
|
||||
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
|
||||
* is in Big Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref cpu_to_be16 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define CPU_TO_BE16(x) SWAPENDIAN_16(x)
|
||||
|
||||
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
|
||||
* is in Big Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref cpu_to_be32 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define CPU_TO_BE32(x) SWAPENDIAN_32(x)
|
||||
|
||||
//! @}
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Function to reverse the byte ordering of the individual bytes in a 16 bit value.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in] Word Word of data whose bytes are to be swapped.
|
||||
*/
|
||||
static inline uint16_t SwapEndian_16(const uint16_t Word) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
|
||||
static inline uint16_t SwapEndian_16(const uint16_t Word)
|
||||
{
|
||||
uint8_t Temp;
|
||||
|
||||
union
|
||||
{
|
||||
uint16_t Word;
|
||||
uint8_t Bytes[2];
|
||||
} Data;
|
||||
|
||||
Data.Word = Word;
|
||||
|
||||
Temp = Data.Bytes[0];
|
||||
Data.Bytes[0] = Data.Bytes[1];
|
||||
Data.Bytes[1] = Temp;
|
||||
|
||||
return Data.Word;
|
||||
}
|
||||
|
||||
/** Function to reverse the byte ordering of the individual bytes in a 32 bit value.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in] DWord Double word of data whose bytes are to be swapped.
|
||||
*/
|
||||
static inline uint32_t SwapEndian_32(const uint32_t DWord) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
|
||||
static inline uint32_t SwapEndian_32(const uint32_t DWord)
|
||||
{
|
||||
uint8_t Temp;
|
||||
|
||||
union
|
||||
{
|
||||
uint32_t DWord;
|
||||
uint8_t Bytes[4];
|
||||
} Data;
|
||||
|
||||
Data.DWord = DWord;
|
||||
|
||||
Temp = Data.Bytes[0];
|
||||
Data.Bytes[0] = Data.Bytes[3];
|
||||
Data.Bytes[3] = Temp;
|
||||
|
||||
Temp = Data.Bytes[1];
|
||||
Data.Bytes[1] = Data.Bytes[2];
|
||||
Data.Bytes[2] = Temp;
|
||||
|
||||
return Data.DWord;
|
||||
}
|
||||
|
||||
/** Function to reverse the byte ordering of the individual bytes in a n byte value.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in,out] Data Pointer to a number containing an even number of bytes to be reversed.
|
||||
* \param[in] Length Length of the data in bytes.
|
||||
*/
|
||||
static inline void SwapEndian_n(void* const Data,
|
||||
uint8_t Length) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline void SwapEndian_n(void* const Data,
|
||||
uint8_t Length)
|
||||
{
|
||||
uint8_t* CurrDataPos = (uint8_t*)Data;
|
||||
|
||||
while (Length > 1)
|
||||
{
|
||||
uint8_t Temp = *CurrDataPos;
|
||||
*CurrDataPos = *(CurrDataPos + Length - 1);
|
||||
*(CurrDataPos + Length - 1) = Temp;
|
||||
|
||||
CurrDataPos++;
|
||||
Length -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Endianness and Byte Ordering macros and functions.
|
||||
*
|
||||
* \copydetails Group_Endianness
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Endianness
|
||||
* \defgroup Group_ByteSwapping Byte Reordering
|
||||
* \brief Macros and functions for forced byte reordering.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Endianness
|
||||
* \defgroup Group_EndianConversion Endianness Conversion
|
||||
* \brief Macros and functions for automatic endianness conversion.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_Endianness Endianness and Byte Ordering
|
||||
* \brief Convenience macros and functions relating to byte (re-)ordering
|
||||
*
|
||||
* Common library convenience macros and functions relating to byte (re-)ordering.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LUFA_ENDIANNESS_H__
|
||||
#define __LUFA_ENDIANNESS_H__
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_COMMON_H)
|
||||
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
|
||||
#endif
|
||||
|
||||
#if !(defined(ARCH_BIG_ENDIAN) || defined(ARCH_LITTLE_ENDIAN))
|
||||
#error ARCH_BIG_ENDIAN or ARCH_LITTLE_ENDIAN not set for the specified architecture.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Swaps the byte ordering of a 16-bit value at compile-time. Do not use this macro for swapping byte orderings
|
||||
* of dynamic values computed at runtime, use \ref SwapEndian_16() instead. The result of this macro can be used
|
||||
* inside struct or other variable initializers outside of a function, something that is not possible with the
|
||||
* inline function variant.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in] x 16-bit value whose byte ordering is to be swapped.
|
||||
*
|
||||
* \return Input value with the byte ordering reversed.
|
||||
*/
|
||||
#define SWAPENDIAN_16(x) (uint16_t)((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
|
||||
|
||||
/** Swaps the byte ordering of a 32-bit value at compile-time. Do not use this macro for swapping byte orderings
|
||||
* of dynamic values computed at runtime- use \ref SwapEndian_32() instead. The result of this macro can be used
|
||||
* inside struct or other variable initializers outside of a function, something that is not possible with the
|
||||
* inline function variant.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in] x 32-bit value whose byte ordering is to be swapped.
|
||||
*
|
||||
* \return Input value with the byte ordering reversed.
|
||||
*/
|
||||
#define SWAPENDIAN_32(x) (uint32_t)((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \
|
||||
(((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))
|
||||
|
||||
#if defined(ARCH_BIG_ENDIAN) && !defined(le16_to_cpu)
|
||||
#define le16_to_cpu(x) SwapEndian_16(x)
|
||||
#define le32_to_cpu(x) SwapEndian_32(x)
|
||||
#define be16_to_cpu(x) x
|
||||
#define be32_to_cpu(x) x
|
||||
#define cpu_to_le16(x) SwapEndian_16(x)
|
||||
#define cpu_to_le32(x) SwapEndian_32(x)
|
||||
#define cpu_to_be16(x) x
|
||||
#define cpu_to_be32(x) x
|
||||
#define LE16_TO_CPU(x) SWAPENDIAN_16(x)
|
||||
#define LE32_TO_CPU(x) SWAPENDIAN_32(x)
|
||||
#define BE16_TO_CPU(x) x
|
||||
#define BE32_TO_CPU(x) x
|
||||
#define CPU_TO_LE16(x) SWAPENDIAN_16(x)
|
||||
#define CPU_TO_LE32(x) SWAPENDIAN_32(x)
|
||||
#define CPU_TO_BE16(x) x
|
||||
#define CPU_TO_BE32(x) x
|
||||
#elif !defined(le16_to_cpu)
|
||||
/** \name Run-time endianness conversion */
|
||||
//@{
|
||||
|
||||
/** Performs a conversion between a Little Endian encoded 16-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref LE16_TO_CPU instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define le16_to_cpu(x) x
|
||||
|
||||
/** Performs a conversion between a Little Endian encoded 32-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref LE32_TO_CPU instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define le32_to_cpu(x) x
|
||||
|
||||
/** Performs a conversion between a Big Endian encoded 16-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref BE16_TO_CPU instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define be16_to_cpu(x) SwapEndian_16(x)
|
||||
|
||||
/** Performs a conversion between a Big Endian encoded 32-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref BE32_TO_CPU instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define be32_to_cpu(x) SwapEndian_32(x)
|
||||
|
||||
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
|
||||
* is in Little Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref CPU_TO_LE16 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define cpu_to_le16(x) x
|
||||
|
||||
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
|
||||
* is in Little Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref CPU_TO_LE32 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define cpu_to_le32(x) x
|
||||
|
||||
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
|
||||
* is in Big Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref CPU_TO_BE16 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define cpu_to_be16(x) SwapEndian_16(x)
|
||||
|
||||
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
|
||||
* is in Big Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for run-time conversion of data - for compile-time endianness
|
||||
* conversion, use \ref CPU_TO_BE32 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define cpu_to_be32(x) SwapEndian_32(x)
|
||||
|
||||
//@}
|
||||
|
||||
/** \name Compile-time endianness conversion */
|
||||
//@{
|
||||
|
||||
/** Performs a conversion between a Little Endian encoded 16-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run time endianness
|
||||
* conversion, use \ref le16_to_cpu instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define LE16_TO_CPU(x) x
|
||||
|
||||
/** Performs a conversion between a Little Endian encoded 32-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run time endianness
|
||||
* conversion, use \ref le32_to_cpu instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define LE32_TO_CPU(x) x
|
||||
|
||||
/** Performs a conversion between a Big Endian encoded 16-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref be16_to_cpu instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define BE16_TO_CPU(x) SWAPENDIAN_16(x)
|
||||
|
||||
/** Performs a conversion between a Big Endian encoded 32-bit piece of data and the
|
||||
* Endianness of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref be32_to_cpu instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define BE32_TO_CPU(x) SWAPENDIAN_32(x)
|
||||
|
||||
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
|
||||
* is in Little Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref cpu_to_le16 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define CPU_TO_LE16(x) x
|
||||
|
||||
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
|
||||
* is in Little Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On little endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref cpu_to_le32 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define CPU_TO_LE32(x) x
|
||||
|
||||
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
|
||||
* is in Big Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref cpu_to_be16 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define CPU_TO_BE16(x) SWAPENDIAN_16(x)
|
||||
|
||||
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
|
||||
* is in Big Endian format regardless of the currently selected CPU architecture.
|
||||
*
|
||||
* On big endian architectures, this macro does nothing.
|
||||
*
|
||||
* \note This macro is designed for compile-time conversion of data - for run-time endianness
|
||||
* conversion, use \ref cpu_to_be32 instead.
|
||||
*
|
||||
* \ingroup Group_EndianConversion
|
||||
*
|
||||
* \param[in] x Data to perform the endianness conversion on.
|
||||
*
|
||||
* \return Endian corrected version of the input value.
|
||||
*/
|
||||
#define CPU_TO_BE32(x) SWAPENDIAN_32(x)
|
||||
|
||||
//! @}
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Function to reverse the byte ordering of the individual bytes in a 16 bit value.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in] Word Word of data whose bytes are to be swapped.
|
||||
*/
|
||||
static inline uint16_t SwapEndian_16(const uint16_t Word) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
|
||||
static inline uint16_t SwapEndian_16(const uint16_t Word)
|
||||
{
|
||||
uint8_t Temp;
|
||||
|
||||
union
|
||||
{
|
||||
uint16_t Word;
|
||||
uint8_t Bytes[2];
|
||||
} Data;
|
||||
|
||||
Data.Word = Word;
|
||||
|
||||
Temp = Data.Bytes[0];
|
||||
Data.Bytes[0] = Data.Bytes[1];
|
||||
Data.Bytes[1] = Temp;
|
||||
|
||||
return Data.Word;
|
||||
}
|
||||
|
||||
/** Function to reverse the byte ordering of the individual bytes in a 32 bit value.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in] DWord Double word of data whose bytes are to be swapped.
|
||||
*/
|
||||
static inline uint32_t SwapEndian_32(const uint32_t DWord) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
|
||||
static inline uint32_t SwapEndian_32(const uint32_t DWord)
|
||||
{
|
||||
uint8_t Temp;
|
||||
|
||||
union
|
||||
{
|
||||
uint32_t DWord;
|
||||
uint8_t Bytes[4];
|
||||
} Data;
|
||||
|
||||
Data.DWord = DWord;
|
||||
|
||||
Temp = Data.Bytes[0];
|
||||
Data.Bytes[0] = Data.Bytes[3];
|
||||
Data.Bytes[3] = Temp;
|
||||
|
||||
Temp = Data.Bytes[1];
|
||||
Data.Bytes[1] = Data.Bytes[2];
|
||||
Data.Bytes[2] = Temp;
|
||||
|
||||
return Data.DWord;
|
||||
}
|
||||
|
||||
/** Function to reverse the byte ordering of the individual bytes in a n byte value.
|
||||
*
|
||||
* \ingroup Group_ByteSwapping
|
||||
*
|
||||
* \param[in,out] Data Pointer to a number containing an even number of bytes to be reversed.
|
||||
* \param[in] Length Length of the data in bytes.
|
||||
*/
|
||||
static inline void SwapEndian_n(void* const Data,
|
||||
uint8_t Length) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline void SwapEndian_n(void* const Data,
|
||||
uint8_t Length)
|
||||
{
|
||||
uint8_t* CurrDataPos = (uint8_t*)Data;
|
||||
|
||||
while (Length > 1)
|
||||
{
|
||||
uint8_t Temp = *CurrDataPos;
|
||||
*CurrDataPos = *(CurrDataPos + Length - 1);
|
||||
*(CurrDataPos + Length - 1) = Temp;
|
||||
|
||||
CurrDataPos++;
|
||||
Length -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,124 +1,124 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Adafruit U4 Breakout board.
|
||||
* \copydetails Group_LEDs_ADAFRUITU4
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_ADAFRUITU4 ADAFRUITU4
|
||||
* \brief Board specific LED driver header for the Adafruit U4 Breakout board.
|
||||
*
|
||||
* Board specific LED driver header for the Adafruit U4 Breakout board (http://ladyada.net/products/atmega32u4breakout).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_ADAFRUITU4_H__
|
||||
#define __LEDS_ADAFRUITU4_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 6)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS LEDS_LED1
|
||||
|
||||
/** LED mask for the none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRE |= LEDS_ALL_LEDS;
|
||||
PORTE &= ~LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTE |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTE &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTE = ((PORTE & ~LEDS_ALL_LEDS) | LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTE = ((PORTE & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTE &= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTE & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Adafruit U4 Breakout board.
|
||||
* \copydetails Group_LEDs_ADAFRUITU4
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_ADAFRUITU4 ADAFRUITU4
|
||||
* \brief Board specific LED driver header for the Adafruit U4 Breakout board.
|
||||
*
|
||||
* Board specific LED driver header for the Adafruit U4 Breakout board (http://ladyada.net/products/atmega32u4breakout).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_ADAFRUITU4_H__
|
||||
#define __LEDS_ADAFRUITU4_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 6)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS LEDS_LED1
|
||||
|
||||
/** LED mask for the none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRE |= LEDS_ALL_LEDS;
|
||||
PORTE &= ~LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTE |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTE &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTE = ((PORTE & ~LEDS_ALL_LEDS) | LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTE = ((PORTE & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTE &= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTE & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,126 +1,126 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the BLACKCAT USB JTAG.
|
||||
* \copydetails Group_LEDs_BLACKCAT
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_BLACKCAT BLACKCAT
|
||||
* \brief Board specific LED driver header for the BLACKCAT USB JTAG.
|
||||
*
|
||||
* Board specific LED driver header for the TCNISO Blackcat USB JTAG (http://www.embeddedcomputers.net/products/BlackcatUSB/.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_BLACKCAT_H__
|
||||
#define __LEDS_BLACKCAT_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 6)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1 << 3)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2)
|
||||
|
||||
/** LED mask for none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRD |= LEDS_ALL_LEDS;
|
||||
PORTD &= ~LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTD = ((PORTD & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTD & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the BLACKCAT USB JTAG.
|
||||
* \copydetails Group_LEDs_BLACKCAT
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_BLACKCAT BLACKCAT
|
||||
* \brief Board specific LED driver header for the BLACKCAT USB JTAG.
|
||||
*
|
||||
* Board specific LED driver header for the TCNISO Blackcat USB JTAG (http://www.embeddedcomputers.net/products/BlackcatUSB/.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_BLACKCAT_H__
|
||||
#define __LEDS_BLACKCAT_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 6)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1 << 3)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2)
|
||||
|
||||
/** LED mask for none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRD |= LEDS_ALL_LEDS;
|
||||
PORTD &= ~LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTD = ((PORTD & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTD & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,126 +1,126 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Maximus.
|
||||
* \copydetails Group_LEDs_MAXIMUS
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_MAXIMUS MAXIMUS
|
||||
* \brief Board specific LED driver header for the Maximus.
|
||||
*
|
||||
* Board specific LED driver header for the Maximus (http://www.avrusb.com/).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_MAXIMUS_H__
|
||||
#define __LEDS_MAXIMUS_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 6)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1 << 7)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2)
|
||||
|
||||
/** LED mask for the none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRB |= LEDS_ALL_LEDS;
|
||||
PORTB &= ~LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB = ((PORTB & ~LEDS_ALL_LEDS) | LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTB = ((PORTB & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTB & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Maximus.
|
||||
* \copydetails Group_LEDs_MAXIMUS
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_MAXIMUS MAXIMUS
|
||||
* \brief Board specific LED driver header for the Maximus.
|
||||
*
|
||||
* Board specific LED driver header for the Maximus (http://www.avrusb.com/).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_MAXIMUS_H__
|
||||
#define __LEDS_MAXIMUS_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 6)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1 << 7)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2)
|
||||
|
||||
/** LED mask for the none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRB |= LEDS_ALL_LEDS;
|
||||
PORTB &= ~LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB = ((PORTB & ~LEDS_ALL_LEDS) | LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTB = ((PORTB & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTB & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the Microsin AVR-USB162 board.
|
||||
* \copydetails Group_Buttons_MICROSIN162
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_MICROSIN162 MICROSIN162
|
||||
* \brief Board specific Buttons driver header for the Microsin AVR-USB162 board.
|
||||
*
|
||||
* Board specific Buttons driver header for the Microsin AVR-USB162 board (http://microsin.ru/content/view/685/44/).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_MICROSIN162_H__
|
||||
#define __BUTTONS_MICROSIN162_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Button mask for the first button on the board. */
|
||||
#define BUTTONS_BUTTON1 (1 << 7)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
DDRD &= ~BUTTONS_BUTTON1;
|
||||
PORTD |= BUTTONS_BUTTON1;
|
||||
}
|
||||
|
||||
static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t Buttons_GetStatus(void)
|
||||
{
|
||||
return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the Microsin AVR-USB162 board.
|
||||
* \copydetails Group_Buttons_MICROSIN162
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_MICROSIN162 MICROSIN162
|
||||
* \brief Board specific Buttons driver header for the Microsin AVR-USB162 board.
|
||||
*
|
||||
* Board specific Buttons driver header for the Microsin AVR-USB162 board (http://microsin.ru/content/view/685/44/).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_MICROSIN162_H__
|
||||
#define __BUTTONS_MICROSIN162_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Button mask for the first button on the board. */
|
||||
#define BUTTONS_BUTTON1 (1 << 7)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
DDRD &= ~BUTTONS_BUTTON1;
|
||||
PORTD |= BUTTONS_BUTTON1;
|
||||
}
|
||||
|
||||
static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t Buttons_GetStatus(void)
|
||||
{
|
||||
return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,124 +1,124 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Microsin AVR-USB162 board.
|
||||
* \copydetails Group_LEDs_MICROSIN162
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_MICROSIN162 MICROSIN162
|
||||
* \brief Board specific LED driver header for the Microsin AVR-USB162 board.
|
||||
*
|
||||
* Board specific LED driver header for the Microsin AVR-USB162 board (http://microsin.ru/content/view/685/44/).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_MICROSIN162_H__
|
||||
#define __LEDS_MICROSIN162_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 4)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS LEDS_LED1
|
||||
|
||||
/** LED mask for none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRD |= LEDS_ALL_LEDS;
|
||||
PORTD |= LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD = ((PORTD | LEDS_ALL_LEDS) & ~LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTD = ((PORTD | LEDMask) & ~ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (~PORTD & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Microsin AVR-USB162 board.
|
||||
* \copydetails Group_LEDs_MICROSIN162
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_MICROSIN162 MICROSIN162
|
||||
* \brief Board specific LED driver header for the Microsin AVR-USB162 board.
|
||||
*
|
||||
* Board specific LED driver header for the Microsin AVR-USB162 board (http://microsin.ru/content/view/685/44/).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_MICROSIN162_H__
|
||||
#define __LEDS_MICROSIN162_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 4)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS LEDS_LED1
|
||||
|
||||
/** LED mask for none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRD |= LEDS_ALL_LEDS;
|
||||
PORTD |= LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD = ((PORTD | LEDS_ALL_LEDS) & ~LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTD = ((PORTD | LEDMask) & ~ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (~PORTD & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the MINIMUS.
|
||||
* \copydetails Group_Buttons_MINIMUS
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_MINIMUS MINIMUS
|
||||
* \brief Board specific Buttons driver header for the MINIMUS.
|
||||
*
|
||||
* Board specific Buttons driver header for the MINIMUS.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_MINIMUS_H__
|
||||
#define __BUTTONS_MINIMUS_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Button mask for the first button on the board. */
|
||||
#define BUTTONS_BUTTON1 (1 << 7)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
DDRD &= ~BUTTONS_BUTTON1;
|
||||
PORTD |= BUTTONS_BUTTON1;
|
||||
}
|
||||
|
||||
static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t Buttons_GetStatus(void)
|
||||
{
|
||||
return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the MINIMUS.
|
||||
* \copydetails Group_Buttons_MINIMUS
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_MINIMUS MINIMUS
|
||||
* \brief Board specific Buttons driver header for the MINIMUS.
|
||||
*
|
||||
* Board specific Buttons driver header for the MINIMUS.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_MINIMUS_H__
|
||||
#define __BUTTONS_MINIMUS_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Button mask for the first button on the board. */
|
||||
#define BUTTONS_BUTTON1 (1 << 7)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
DDRD &= ~BUTTONS_BUTTON1;
|
||||
PORTD |= BUTTONS_BUTTON1;
|
||||
}
|
||||
|
||||
static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t Buttons_GetStatus(void)
|
||||
{
|
||||
return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,126 +1,126 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the MINIMUS.
|
||||
* \copydetails Group_LEDs_MINIMUS
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_MINIMUS MINIMUS
|
||||
* \brief Board specific LED driver header for the MINIMUS.
|
||||
*
|
||||
* Board specific LED driver header for the Minimus USB (http://www.minimususb.com/).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_MINIMUS_H__
|
||||
#define __LEDS_MINIMUS_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 5)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1 << 6)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2)
|
||||
|
||||
/** LED mask for the none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 1
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRD |= LEDS_ALL_LEDS;
|
||||
PORTD |= LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD = ((PORTD | LEDS_ALL_LEDS) & ~LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTD = ((PORTD & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTD & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the MINIMUS.
|
||||
* \copydetails Group_LEDs_MINIMUS
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_MINIMUS MINIMUS
|
||||
* \brief Board specific LED driver header for the MINIMUS.
|
||||
*
|
||||
* Board specific LED driver header for the Minimus USB (http://www.minimususb.com/).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_MINIMUS_H__
|
||||
#define __LEDS_MINIMUS_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 5)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1 << 6)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2)
|
||||
|
||||
/** LED mask for the none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 1
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRD |= LEDS_ALL_LEDS;
|
||||
PORTD |= LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD = ((PORTD | LEDS_ALL_LEDS) & ~LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTD = ((PORTD & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTD ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTD & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,124 +1,124 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Sparkfun ATMEGA8U2 breakout board.
|
||||
* \copydetails Group_LEDs_SPARKFUN8U2
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_SPARKFUN8U2 SPARKFUN8U2
|
||||
* \brief Board specific LED driver header for the Sparkfun ATMEGA8U2 breakout board.
|
||||
*
|
||||
* Board specific LED driver header for the Sparkfun ATMEGA8U2 breakout board (http://www.sparkfun.com/products/10277).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_SPARKFUN8U2_H__
|
||||
#define __LEDS_SPARKFUN8U2_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 4)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS LEDS_LED1
|
||||
|
||||
/** LED mask for none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRB |= LEDS_ALL_LEDS;
|
||||
PORTB |= LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB = ((PORTB | LEDS_ALL_LEDS) & ~LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTB = ((PORTB | LEDMask) & ~ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (~PORTB & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Sparkfun ATMEGA8U2 breakout board.
|
||||
* \copydetails Group_LEDs_SPARKFUN8U2
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_SPARKFUN8U2 SPARKFUN8U2
|
||||
* \brief Board specific LED driver header for the Sparkfun ATMEGA8U2 breakout board.
|
||||
*
|
||||
* Board specific LED driver header for the Sparkfun ATMEGA8U2 breakout board (http://www.sparkfun.com/products/10277).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_SPARKFUN8U2_H__
|
||||
#define __LEDS_SPARKFUN8U2_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 4)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS LEDS_LED1
|
||||
|
||||
/** LED mask for none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRB |= LEDS_ALL_LEDS;
|
||||
PORTB |= LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB = ((PORTB | LEDS_ALL_LEDS) & ~LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTB = ((PORTB | LEDMask) & ~ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTB ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (~PORTB & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the TUL.
|
||||
* \copydetails Group_Buttons_TUL
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_TUL TUL
|
||||
* \brief Board specific Buttons driver header for the TUL.
|
||||
*
|
||||
* Board specific Buttons driver header for the Busware TUL (http://www.busware.de/tiki-index.php?page=TUL).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_TUL_H__
|
||||
#define __BUTTONS_TUL_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Button mask for the first button on the board. */
|
||||
#define BUTTONS_BUTTON1 (1 << 2)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
DDRE &= ~BUTTONS_BUTTON1;
|
||||
PORTE |= BUTTONS_BUTTON1;
|
||||
}
|
||||
|
||||
static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t Buttons_GetStatus(void)
|
||||
{
|
||||
return ((PINE & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the TUL.
|
||||
* \copydetails Group_Buttons_TUL
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_TUL TUL
|
||||
* \brief Board specific Buttons driver header for the TUL.
|
||||
*
|
||||
* Board specific Buttons driver header for the Busware TUL (http://www.busware.de/tiki-index.php?page=TUL).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_TUL_H__
|
||||
#define __BUTTONS_TUL_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Button mask for the first button on the board. */
|
||||
#define BUTTONS_BUTTON1 (1 << 2)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
DDRE &= ~BUTTONS_BUTTON1;
|
||||
PORTE |= BUTTONS_BUTTON1;
|
||||
}
|
||||
|
||||
static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t Buttons_GetStatus(void)
|
||||
{
|
||||
return ((PINE & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,124 +1,124 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Busware TUL.
|
||||
* \copydetails Group_LEDs_TUL
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_TUL TUL
|
||||
* \brief Board specific LED driver header for the Busware TUL.
|
||||
*
|
||||
* Board specific LED driver header for the Busware TUL (http://www.busware.de/tiki-index.php?page=TUL).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_TUL_H__
|
||||
#define __LEDS_TUL_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 0)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS LEDS_LED1
|
||||
|
||||
/** LED mask for the none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRF |= LEDS_ALL_LEDS;
|
||||
PORTF &= ~LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTF |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTF &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTF = ((PORTF & ~LEDS_ALL_LEDS) | LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTF = ((PORTF & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTF ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTF & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Busware TUL.
|
||||
* \copydetails Group_LEDs_TUL
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_TUL TUL
|
||||
* \brief Board specific LED driver header for the Busware TUL.
|
||||
*
|
||||
* Board specific LED driver header for the Busware TUL (http://www.busware.de/tiki-index.php?page=TUL).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_TUL_H__
|
||||
#define __LEDS_TUL_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1 << 0)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS LEDS_LED1
|
||||
|
||||
/** LED mask for the none of the board LEDs. */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
DDRF |= LEDS_ALL_LEDS;
|
||||
PORTF &= ~LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTF |= LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTF &= ~LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTF = ((PORTF & ~LEDS_ALL_LEDS) | LEDMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
|
||||
const uint8_t ActiveMask)
|
||||
{
|
||||
PORTF = ((PORTF & ~LEDMask) | ActiveMask);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
|
||||
{
|
||||
PORTF ^= LEDMask;
|
||||
}
|
||||
|
||||
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (PORTF & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1100.
|
||||
* \copydetails Group_Buttons_EVK1100
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_EVK1100 EVK1100
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1100.
|
||||
*
|
||||
* Board specific Buttons driver header for the Atmel EVK1100.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_EVK1100_H__
|
||||
#define __BUTTONS_EVK1100_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define BUTTONS_PORT 2
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask of the first button on the board */
|
||||
#define BUTTONS_BUTTON1 (1UL << 24)
|
||||
|
||||
/** Mask of the second button on the board */
|
||||
#define BUTTONS_BUTTON2 (1UL << 21)
|
||||
|
||||
/** Mask of the third button on the board */
|
||||
#define BUTTONS_BUTTON3 (1UL << 18)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[BUTTONS_PORT].gpers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
AVR32_GPIO.port[BUTTONS_PORT].puers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
}
|
||||
|
||||
static inline uint32_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Buttons_GetStatus(void)
|
||||
{
|
||||
return (~(AVR32_GPIO.port[JOY_MOVE_PORT].pvr & (BUTTONS_BUTTON1 | BUTTONS_BUTTON2)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1100.
|
||||
* \copydetails Group_Buttons_EVK1100
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_EVK1100 EVK1100
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1100.
|
||||
*
|
||||
* Board specific Buttons driver header for the Atmel EVK1100.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_EVK1100_H__
|
||||
#define __BUTTONS_EVK1100_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define BUTTONS_PORT 2
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask of the first button on the board */
|
||||
#define BUTTONS_BUTTON1 (1UL << 24)
|
||||
|
||||
/** Mask of the second button on the board */
|
||||
#define BUTTONS_BUTTON2 (1UL << 21)
|
||||
|
||||
/** Mask of the third button on the board */
|
||||
#define BUTTONS_BUTTON3 (1UL << 18)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[BUTTONS_PORT].gpers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
AVR32_GPIO.port[BUTTONS_PORT].puers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
}
|
||||
|
||||
static inline uint32_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Buttons_GetStatus(void)
|
||||
{
|
||||
return (~(AVR32_GPIO.port[JOY_MOVE_PORT].pvr & (BUTTONS_BUTTON1 | BUTTONS_BUTTON2)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,110 +1,110 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific joystick driver header for the Atmel EVK1100.
|
||||
* \copydetails Group_Joystick_EVK1100
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the joystick driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Joystick.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Joystick
|
||||
* \defgroup Group_Joystick_EVK1100 EVK1100
|
||||
* \brief Board specific joystick driver header for the Atmel EVK1100.
|
||||
*
|
||||
* Board specific joystick driver header for the Atmel EVK1100.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __JOYSTICK_EVK1100_H__
|
||||
#define __JOYSTICK_EVK1100_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_JOYSTICK_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define JOY_PORT 0
|
||||
#define JOY_MASK ((1UL << 28) | (1UL << 27) | (1UL << 26) | (1UL << 25) | (1UL << 20))
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask for the joystick being pushed in the left direction. */
|
||||
#define JOY_LEFT (1UL << 25)
|
||||
|
||||
/** Mask for the joystick being pushed in the upward direction. */
|
||||
#define JOY_UP (1UL << 26)
|
||||
|
||||
/** Mask for the joystick being pushed in the right direction. */
|
||||
#define JOY_RIGHT (1UL << 28)
|
||||
|
||||
/** Mask for the joystick being pushed in the downward direction. */
|
||||
#define JOY_DOWN (1UL << 27)
|
||||
|
||||
/** Mask for the joystick being pushed inward. */
|
||||
#define JOY_PRESS (1UL << 20)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Joystick_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[JOY_PORT].gpers = JOY_MASK;
|
||||
AVR32_GPIO.port[JOY_PORT].gpers = JOY_MASK;
|
||||
};
|
||||
|
||||
static inline uint32_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Joystick_GetStatus(void)
|
||||
{
|
||||
return (uint32_t)(~(AVR32_GPIO.port[JOY_PORT].pvr & JOY_MASK));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific joystick driver header for the Atmel EVK1100.
|
||||
* \copydetails Group_Joystick_EVK1100
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the joystick driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Joystick.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Joystick
|
||||
* \defgroup Group_Joystick_EVK1100 EVK1100
|
||||
* \brief Board specific joystick driver header for the Atmel EVK1100.
|
||||
*
|
||||
* Board specific joystick driver header for the Atmel EVK1100.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __JOYSTICK_EVK1100_H__
|
||||
#define __JOYSTICK_EVK1100_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_JOYSTICK_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define JOY_PORT 0
|
||||
#define JOY_MASK ((1UL << 28) | (1UL << 27) | (1UL << 26) | (1UL << 25) | (1UL << 20))
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask for the joystick being pushed in the left direction. */
|
||||
#define JOY_LEFT (1UL << 25)
|
||||
|
||||
/** Mask for the joystick being pushed in the upward direction. */
|
||||
#define JOY_UP (1UL << 26)
|
||||
|
||||
/** Mask for the joystick being pushed in the right direction. */
|
||||
#define JOY_RIGHT (1UL << 28)
|
||||
|
||||
/** Mask for the joystick being pushed in the downward direction. */
|
||||
#define JOY_DOWN (1UL << 27)
|
||||
|
||||
/** Mask for the joystick being pushed inward. */
|
||||
#define JOY_PRESS (1UL << 20)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Joystick_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[JOY_PORT].gpers = JOY_MASK;
|
||||
AVR32_GPIO.port[JOY_PORT].gpers = JOY_MASK;
|
||||
};
|
||||
|
||||
static inline uint32_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Joystick_GetStatus(void)
|
||||
{
|
||||
return (uint32_t)(~(AVR32_GPIO.port[JOY_PORT].pvr & JOY_MASK));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,153 +1,153 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Atmel EVK1100.
|
||||
* \copydetails Group_LEDs_EVK1100
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_EVK1100 EVK1100
|
||||
* \brief Board specific LED driver header for the Atmel EVK1100.
|
||||
*
|
||||
* Board specific LED driver header for the Atmel EVK1100.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_EVK1100_H__
|
||||
#define __LEDS_EVK1100_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define LEDS_PORT 1
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1UL << 19)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1UL << 20)
|
||||
|
||||
/** LED mask for the third LED on the board. */
|
||||
#define LEDS_LED3 (1UL << 21)
|
||||
|
||||
/** LED mask for the fourth LED on the board. */
|
||||
#define LEDS_LED4 (1UL << 22)
|
||||
|
||||
/** LED mask for the fifth LED on the board. */
|
||||
#define LEDS_LED5 (1UL << 27)
|
||||
|
||||
/** LED mask for the sixth LED on the board. */
|
||||
#define LEDS_LED6 (1UL << 28)
|
||||
|
||||
/** LED mask for the seventh LED on the board. */
|
||||
#define LEDS_LED7 (1UL << 29)
|
||||
|
||||
/** LED mask for the eighth LED on the board. */
|
||||
#define LEDS_LED8 (1UL << 30)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4 \
|
||||
LEDS_LED5 | LEDS_LED6 | LEDS_LED7 | LEDS_LED8)
|
||||
|
||||
/** LED mask for the none of the board LEDs */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].gpers = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].oders = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint32_t LEDMask, const uint32_t ActiveMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDMask;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = ActiveMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrt = LEDMask;
|
||||
}
|
||||
|
||||
static inline uint32_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (~AVR32_GPIO.port[LEDS_PORT].ovr & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Atmel EVK1100.
|
||||
* \copydetails Group_LEDs_EVK1100
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_EVK1100 EVK1100
|
||||
* \brief Board specific LED driver header for the Atmel EVK1100.
|
||||
*
|
||||
* Board specific LED driver header for the Atmel EVK1100.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_EVK1100_H__
|
||||
#define __LEDS_EVK1100_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define LEDS_PORT 1
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1UL << 19)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1UL << 20)
|
||||
|
||||
/** LED mask for the third LED on the board. */
|
||||
#define LEDS_LED3 (1UL << 21)
|
||||
|
||||
/** LED mask for the fourth LED on the board. */
|
||||
#define LEDS_LED4 (1UL << 22)
|
||||
|
||||
/** LED mask for the fifth LED on the board. */
|
||||
#define LEDS_LED5 (1UL << 27)
|
||||
|
||||
/** LED mask for the sixth LED on the board. */
|
||||
#define LEDS_LED6 (1UL << 28)
|
||||
|
||||
/** LED mask for the seventh LED on the board. */
|
||||
#define LEDS_LED7 (1UL << 29)
|
||||
|
||||
/** LED mask for the eighth LED on the board. */
|
||||
#define LEDS_LED8 (1UL << 30)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4 \
|
||||
LEDS_LED5 | LEDS_LED6 | LEDS_LED7 | LEDS_LED8)
|
||||
|
||||
/** LED mask for the none of the board LEDs */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].gpers = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].oders = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint32_t LEDMask, const uint32_t ActiveMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDMask;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = ActiveMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrt = LEDMask;
|
||||
}
|
||||
|
||||
static inline uint32_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (~AVR32_GPIO.port[LEDS_PORT].ovr & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,100 +1,100 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1101.
|
||||
* \copydetails Group_Buttons_EVK1101
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_EVK1101 EVK1101
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1101.
|
||||
*
|
||||
* Board specific Buttons driver header for the Atmel EVK1101.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_EVK1101_H__
|
||||
#define __BUTTONS_EVK1101_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define BUTTONS_PORT 1
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask of the first button on the board */
|
||||
#define BUTTONS_BUTTON1 (1UL << 2)
|
||||
|
||||
/** Mask of the second button on the board */
|
||||
#define BUTTONS_BUTTON2 (1UL << 3)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[BUTTONS_PORT].gpers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
AVR32_GPIO.port[BUTTONS_PORT].puers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
}
|
||||
|
||||
static inline uint32_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Buttons_GetStatus(void)
|
||||
{
|
||||
return (~(AVR32_GPIO.port[JOY_MOVE_PORT].pvr & (BUTTONS_BUTTON1 | BUTTONS_BUTTON2)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1101.
|
||||
* \copydetails Group_Buttons_EVK1101
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_EVK1101 EVK1101
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1101.
|
||||
*
|
||||
* Board specific Buttons driver header for the Atmel EVK1101.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_EVK1101_H__
|
||||
#define __BUTTONS_EVK1101_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define BUTTONS_PORT 1
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask of the first button on the board */
|
||||
#define BUTTONS_BUTTON1 (1UL << 2)
|
||||
|
||||
/** Mask of the second button on the board */
|
||||
#define BUTTONS_BUTTON2 (1UL << 3)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[BUTTONS_PORT].gpers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
AVR32_GPIO.port[BUTTONS_PORT].puers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
}
|
||||
|
||||
static inline uint32_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Buttons_GetStatus(void)
|
||||
{
|
||||
return (~(AVR32_GPIO.port[JOY_MOVE_PORT].pvr & (BUTTONS_BUTTON1 | BUTTONS_BUTTON2)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,116 +1,116 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific joystick driver header for the Atmel EVK1101.
|
||||
* \copydetails Group_Joystick_EVK1101
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the joystick driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Joystick.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Joystick
|
||||
* \defgroup Group_Joystick_EVK1101 EVK1101
|
||||
* \brief Board specific joystick driver header for the Atmel EVK1101.
|
||||
*
|
||||
* Board specific joystick driver header for the Atmel EVK1101.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __JOYSTICK_EVK1101_H__
|
||||
#define __JOYSTICK_EVK1101_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_JOYSTICK_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define JOY_MOVE_PORT 1
|
||||
#define JOY_MOVE_MASK ((1UL << 6) | (1UL << 7) | (1UL << 8) | (1UL << 9))
|
||||
#define JOY_PRESS_PORT 0
|
||||
#define JOY_PRESS_MASK (1UL << 13)
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask for the joystick being pushed in the left direction. */
|
||||
#define JOY_LEFT (1UL << 6)
|
||||
|
||||
/** Mask for the joystick being pushed in the upward direction. */
|
||||
#define JOY_UP (1UL << 7)
|
||||
|
||||
/** Mask for the joystick being pushed in the right direction. */
|
||||
#define JOY_RIGHT (1UL << 9)
|
||||
|
||||
/** Mask for the joystick being pushed in the downward direction. */
|
||||
#define JOY_DOWN (1UL << 8)
|
||||
|
||||
/** Mask for the joystick being pushed inward. */
|
||||
#define JOY_PRESS (1UL << 13)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Joystick_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[JOY_MOVE_PORT].gpers = JOY_MOVE_MASK;
|
||||
AVR32_GPIO.port[JOY_PRESS_PORT].gpers = JOY_PRESS_MASK;
|
||||
|
||||
AVR32_GPIO.port[JOY_MOVE_PORT].puers = JOY_MOVE_MASK;
|
||||
AVR32_GPIO.port[JOY_PRESS_PORT].puers = JOY_PRESS_MASK;
|
||||
};
|
||||
|
||||
static inline uint32_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Joystick_GetStatus(void)
|
||||
{
|
||||
return (uint32_t)(~((AVR32_GPIO.port[JOY_MOVE_PORT].pvr & JOY_MOVE_MASK) |
|
||||
(AVR32_GPIO.port[JOY_PRESS_PORT].pvr & JOY_PRESS_MASK)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific joystick driver header for the Atmel EVK1101.
|
||||
* \copydetails Group_Joystick_EVK1101
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the joystick driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Joystick.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Joystick
|
||||
* \defgroup Group_Joystick_EVK1101 EVK1101
|
||||
* \brief Board specific joystick driver header for the Atmel EVK1101.
|
||||
*
|
||||
* Board specific joystick driver header for the Atmel EVK1101.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __JOYSTICK_EVK1101_H__
|
||||
#define __JOYSTICK_EVK1101_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_JOYSTICK_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define JOY_MOVE_PORT 1
|
||||
#define JOY_MOVE_MASK ((1UL << 6) | (1UL << 7) | (1UL << 8) | (1UL << 9))
|
||||
#define JOY_PRESS_PORT 0
|
||||
#define JOY_PRESS_MASK (1UL << 13)
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask for the joystick being pushed in the left direction. */
|
||||
#define JOY_LEFT (1UL << 6)
|
||||
|
||||
/** Mask for the joystick being pushed in the upward direction. */
|
||||
#define JOY_UP (1UL << 7)
|
||||
|
||||
/** Mask for the joystick being pushed in the right direction. */
|
||||
#define JOY_RIGHT (1UL << 9)
|
||||
|
||||
/** Mask for the joystick being pushed in the downward direction. */
|
||||
#define JOY_DOWN (1UL << 8)
|
||||
|
||||
/** Mask for the joystick being pushed inward. */
|
||||
#define JOY_PRESS (1UL << 13)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Joystick_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[JOY_MOVE_PORT].gpers = JOY_MOVE_MASK;
|
||||
AVR32_GPIO.port[JOY_PRESS_PORT].gpers = JOY_PRESS_MASK;
|
||||
|
||||
AVR32_GPIO.port[JOY_MOVE_PORT].puers = JOY_MOVE_MASK;
|
||||
AVR32_GPIO.port[JOY_PRESS_PORT].puers = JOY_PRESS_MASK;
|
||||
};
|
||||
|
||||
static inline uint32_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Joystick_GetStatus(void)
|
||||
{
|
||||
return (uint32_t)(~((AVR32_GPIO.port[JOY_MOVE_PORT].pvr & JOY_MOVE_MASK) |
|
||||
(AVR32_GPIO.port[JOY_PRESS_PORT].pvr & JOY_PRESS_MASK)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,140 +1,140 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Atmel EVK1101.
|
||||
* \copydetails Group_LEDs_EVK1101
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_EVK1101 EVK1101
|
||||
* \brief Board specific LED driver header for the Atmel EVK1101.
|
||||
*
|
||||
* Board specific LED driver header for the Atmel EVK1101.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_EVK1101_H__
|
||||
#define __LEDS_EVK1101_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define LEDS_PORT 0
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1UL << 7)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1UL << 8)
|
||||
|
||||
/** LED mask for the third LED on the board. */
|
||||
#define LEDS_LED3 (1UL << 21)
|
||||
|
||||
/** LED mask for the fourth LED on the board. */
|
||||
#define LEDS_LED4 (1UL << 22)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4)
|
||||
|
||||
/** LED mask for the none of the board LEDs */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].gpers = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].oders = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint32_t LEDMask, const uint32_t ActiveMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDMask;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = ActiveMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrt = LEDMask;
|
||||
}
|
||||
|
||||
static inline uint32_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (~AVR32_GPIO.port[LEDS_PORT].ovr & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Atmel EVK1101.
|
||||
* \copydetails Group_LEDs_EVK1101
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_EVK1101 EVK1101
|
||||
* \brief Board specific LED driver header for the Atmel EVK1101.
|
||||
*
|
||||
* Board specific LED driver header for the Atmel EVK1101.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_EVK1101_H__
|
||||
#define __LEDS_EVK1101_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define LEDS_PORT 0
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1UL << 7)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1UL << 8)
|
||||
|
||||
/** LED mask for the third LED on the board. */
|
||||
#define LEDS_LED3 (1UL << 21)
|
||||
|
||||
/** LED mask for the fourth LED on the board. */
|
||||
#define LEDS_LED4 (1UL << 22)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4)
|
||||
|
||||
/** LED mask for the none of the board LEDs */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].gpers = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].oders = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDS_ALL_LEDS;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDS_ALL_LEDS;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = LEDMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint32_t LEDMask, const uint32_t ActiveMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrs = LEDMask;
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrc = ActiveMask;
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[LEDS_PORT].ovrt = LEDMask;
|
||||
}
|
||||
|
||||
static inline uint32_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return (~AVR32_GPIO.port[LEDS_PORT].ovr & LEDS_ALL_LEDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,97 +1,97 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1104.
|
||||
* \copydetails Group_Buttons_EVK1104
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_EVK1104 EVK1104
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1104.
|
||||
*
|
||||
* Board specific Buttons driver header for the Atmel EVK1104.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_EVK1104_H__
|
||||
#define __BUTTONS_EVK1104_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define BUTTONS_PORT 1
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask of the first button on the board */
|
||||
#define BUTTONS_BUTTON1 (1UL << 10)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[BUTTONS_PORT].gpers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
AVR32_GPIO.port[BUTTONS_PORT].puers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
}
|
||||
|
||||
static inline uint32_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Buttons_GetStatus(void)
|
||||
{
|
||||
return (~(AVR32_GPIO.port[JOY_MOVE_PORT].pvr & (BUTTONS_BUTTON1 | BUTTONS_BUTTON2)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1104.
|
||||
* \copydetails Group_Buttons_EVK1104
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the Buttons driver
|
||||
* dispatch header located in LUFA/Drivers/Board/Buttons.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Buttons
|
||||
* \defgroup Group_Buttons_EVK1104 EVK1104
|
||||
* \brief Board specific Buttons driver header for the Atmel EVK1104.
|
||||
*
|
||||
* Board specific Buttons driver header for the Atmel EVK1104.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __BUTTONS_EVK1104_H__
|
||||
#define __BUTTONS_EVK1104_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_BUTTONS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define BUTTONS_PORT 1
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Mask of the first button on the board */
|
||||
#define BUTTONS_BUTTON1 (1UL << 10)
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void Buttons_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[BUTTONS_PORT].gpers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
AVR32_GPIO.port[BUTTONS_PORT].puers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2);
|
||||
}
|
||||
|
||||
static inline uint32_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t Buttons_GetStatus(void)
|
||||
{
|
||||
return (~(AVR32_GPIO.port[JOY_MOVE_PORT].pvr & (BUTTONS_BUTTON1 | BUTTONS_BUTTON2)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,154 +1,154 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Atmel EVK1104.
|
||||
* \copydetails Group_LEDs_EVK1104
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_EVK1104 EVK1104
|
||||
* \brief Board specific LED driver header for the Atmel EVK1104.
|
||||
*
|
||||
* Board specific LED driver header for the Atmel EVK1104.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_EVK1104_H__
|
||||
#define __LEDS_EVK1104_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define LEDS_LEDMASK2 (1UL << 3)
|
||||
#define LEDS_LEDMASK3 ((1UL << 9) | (1UL << 6) | (1UL << 5))
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1UL << 3)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1UL << 5)
|
||||
|
||||
/** LED mask for the third LED on the board. */
|
||||
#define LEDS_LED3 (1UL << 9)
|
||||
|
||||
/** LED mask for the fourth LED on the board. */
|
||||
#define LEDS_LED4 (1UL << 6)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4)
|
||||
|
||||
/** LED mask for the none of the board LEDs */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[2].gpers = LEDS_LEDMASK2;
|
||||
AVR32_GPIO.port[2].oders = LEDS_LEDMASK2;
|
||||
AVR32_GPIO.port[2].ovrs = LEDS_LEDMASK2;
|
||||
|
||||
AVR32_GPIO.port[3].gpers = LEDS_LEDMASK3;
|
||||
AVR32_GPIO.port[3].oders = LEDS_LEDMASK3;
|
||||
AVR32_GPIO.port[3].ovrs = LEDS_LEDMASK3;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrc = (LEDMask & LEDS_LEDMASK2);
|
||||
AVR32_GPIO.port[3].ovrc = (LEDMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrs = (LEDMask & LEDS_LEDMASK2);
|
||||
AVR32_GPIO.port[3].ovrs = (LEDMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrs = LEDS_LEDMASK2;
|
||||
AVR32_GPIO.port[2].ovrc = (LEDMask & LEDS_LEDMASK2);
|
||||
|
||||
AVR32_GPIO.port[3].ovrs = LEDS_LEDMASK3;
|
||||
AVR32_GPIO.port[3].ovrc = (LEDMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint32_t LEDMask, const uint32_t ActiveMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrs = (LEDMask & LEDS_LEDMASK2);
|
||||
AVR32_GPIO.port[2].ovrc = (ActiveMask & LEDS_LEDMASK2);
|
||||
|
||||
AVR32_GPIO.port[3].ovrs = (LEDMask & LEDS_LEDMASK3);
|
||||
AVR32_GPIO.port[3].ovrc = (ActiveMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrt = (LEDMask & LEDS_LEDMASK2);
|
||||
AVR32_GPIO.port[3].ovrt = (LEDMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline uint32_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return ((~AVR32_GPIO.port[2].ovr & LEDS_LEDMASK2) | (~AVR32_GPIO.port[3].ovr & LEDS_LEDMASK3));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Board specific LED driver header for the Atmel EVK1104.
|
||||
* \copydetails Group_LEDs_EVK1104
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the LEDs driver
|
||||
* dispatch header located in LUFA/Drivers/Board/LEDs.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_LEDs
|
||||
* \defgroup Group_LEDs_EVK1104 EVK1104
|
||||
* \brief Board specific LED driver header for the Atmel EVK1104.
|
||||
*
|
||||
* Board specific LED driver header for the Atmel EVK1104.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LEDS_EVK1104_H__
|
||||
#define __LEDS_EVK1104_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_LEDS_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define LEDS_LEDMASK2 (1UL << 3)
|
||||
#define LEDS_LEDMASK3 ((1UL << 9) | (1UL << 6) | (1UL << 5))
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** LED mask for the first LED on the board. */
|
||||
#define LEDS_LED1 (1UL << 3)
|
||||
|
||||
/** LED mask for the second LED on the board. */
|
||||
#define LEDS_LED2 (1UL << 5)
|
||||
|
||||
/** LED mask for the third LED on the board. */
|
||||
#define LEDS_LED3 (1UL << 9)
|
||||
|
||||
/** LED mask for the fourth LED on the board. */
|
||||
#define LEDS_LED4 (1UL << 6)
|
||||
|
||||
/** LED mask for all the LEDs on the board. */
|
||||
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4)
|
||||
|
||||
/** LED mask for the none of the board LEDs */
|
||||
#define LEDS_NO_LEDS 0
|
||||
|
||||
/* Inline Functions: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
static inline void LEDs_Init(void)
|
||||
{
|
||||
AVR32_GPIO.port[2].gpers = LEDS_LEDMASK2;
|
||||
AVR32_GPIO.port[2].oders = LEDS_LEDMASK2;
|
||||
AVR32_GPIO.port[2].ovrs = LEDS_LEDMASK2;
|
||||
|
||||
AVR32_GPIO.port[3].gpers = LEDS_LEDMASK3;
|
||||
AVR32_GPIO.port[3].oders = LEDS_LEDMASK3;
|
||||
AVR32_GPIO.port[3].ovrs = LEDS_LEDMASK3;
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOnLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrc = (LEDMask & LEDS_LEDMASK2);
|
||||
AVR32_GPIO.port[3].ovrc = (LEDMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline void LEDs_TurnOffLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrs = (LEDMask & LEDS_LEDMASK2);
|
||||
AVR32_GPIO.port[3].ovrs = (LEDMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline void LEDs_SetAllLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrs = LEDS_LEDMASK2;
|
||||
AVR32_GPIO.port[2].ovrc = (LEDMask & LEDS_LEDMASK2);
|
||||
|
||||
AVR32_GPIO.port[3].ovrs = LEDS_LEDMASK3;
|
||||
AVR32_GPIO.port[3].ovrc = (LEDMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline void LEDs_ChangeLEDs(const uint32_t LEDMask, const uint32_t ActiveMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrs = (LEDMask & LEDS_LEDMASK2);
|
||||
AVR32_GPIO.port[2].ovrc = (ActiveMask & LEDS_LEDMASK2);
|
||||
|
||||
AVR32_GPIO.port[3].ovrs = (LEDMask & LEDS_LEDMASK3);
|
||||
AVR32_GPIO.port[3].ovrc = (ActiveMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline void LEDs_ToggleLEDs(const uint32_t LEDMask)
|
||||
{
|
||||
AVR32_GPIO.port[2].ovrt = (LEDMask & LEDS_LEDMASK2);
|
||||
AVR32_GPIO.port[3].ovrt = (LEDMask & LEDS_LEDMASK3);
|
||||
}
|
||||
|
||||
static inline uint32_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint32_t LEDs_GetLEDs(void)
|
||||
{
|
||||
return ((~AVR32_GPIO.port[2].ovr & LEDS_LEDMASK2) | (~AVR32_GPIO.port[3].ovr & LEDS_LEDMASK3));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Command constants for the Atmel AT45DB321C Dataflash.
|
||||
* \copydetails Group_AT45DB321C
|
||||
*/
|
||||
|
||||
/** \ingroup Group_MiscDrivers
|
||||
* \defgroup Group_AT45DB321C Atmel AT45DB321C Dataflash Commands
|
||||
* \brief Command constants for the Atmel AT45DB321C Dataflash.
|
||||
*
|
||||
* Dataflash command constants for the Atmel AT45DB321C Dataflash IC.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __AT45DB321C_CMDS_H__
|
||||
#define __AT45DB321C_CMDS_H__
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name Dataflash Status Values */
|
||||
//@{
|
||||
#define DF_STATUS_READY (1 << 7)
|
||||
#define DF_STATUS_COMPMISMATCH (1 << 6)
|
||||
#define DF_STATUS_SECTORPROTECTION_ON (1 << 1)
|
||||
//@}
|
||||
|
||||
#define DF_MANUFACTURER_ATMEL 0x1F
|
||||
|
||||
/** \name Dataflash Commands */
|
||||
//@{
|
||||
#define DF_CMD_GETSTATUS 0xD7
|
||||
|
||||
#define DF_CMD_MAINMEMTOBUFF1 0x53
|
||||
#define DF_CMD_MAINMEMTOBUFF2 0x55
|
||||
#define DF_CMD_MAINMEMTOBUFF1COMP 0x60
|
||||
#define DF_CMD_MAINMEMTOBUFF2COMP 0x61
|
||||
#define DF_CMD_AUTOREWRITEBUFF1 0x58
|
||||
#define DF_CMD_AUTOREWRITEBUFF2 0x59
|
||||
|
||||
#define DF_CMD_MAINMEMPAGEREAD 0xD2
|
||||
#define DF_CMD_CONTARRAYREAD_LF 0xE8
|
||||
#define DF_CMD_BUFF1READ_LF 0xD4
|
||||
#define DF_CMD_BUFF2READ_LF 0xD6
|
||||
|
||||
#define DF_CMD_BUFF1WRITE 0x84
|
||||
#define DF_CMD_BUFF2WRITE 0x87
|
||||
#define DF_CMD_BUFF1TOMAINMEMWITHERASE 0x83
|
||||
#define DF_CMD_BUFF2TOMAINMEMWITHERASE 0x86
|
||||
#define DF_CMD_BUFF1TOMAINMEM 0x88
|
||||
#define DF_CMD_BUFF2TOMAINMEM 0x89
|
||||
#define DF_CMD_MAINMEMPAGETHROUGHBUFF1 0x82
|
||||
#define DF_CMD_MAINMEMPAGETHROUGHBUFF2 0x85
|
||||
|
||||
#define DF_CMD_PAGEERASE 0x81
|
||||
#define DF_CMD_BLOCKERASE 0x50
|
||||
|
||||
#define DF_CMD_SECTORPROTECTIONOFF ((char[]){0x3D, 0x2A, 0x7F, 0xCF})
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE1 0x3D
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE2 0x2A
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE3 0x7F
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE4 0xCF
|
||||
|
||||
#define DF_CMD_READMANUFACTURERDEVICEINFO 0x9F
|
||||
//@}
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Command constants for the Atmel AT45DB321C Dataflash.
|
||||
* \copydetails Group_AT45DB321C
|
||||
*/
|
||||
|
||||
/** \ingroup Group_MiscDrivers
|
||||
* \defgroup Group_AT45DB321C Atmel AT45DB321C Dataflash Commands
|
||||
* \brief Command constants for the Atmel AT45DB321C Dataflash.
|
||||
*
|
||||
* Dataflash command constants for the Atmel AT45DB321C Dataflash IC.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __AT45DB321C_CMDS_H__
|
||||
#define __AT45DB321C_CMDS_H__
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name Dataflash Status Values */
|
||||
//@{
|
||||
#define DF_STATUS_READY (1 << 7)
|
||||
#define DF_STATUS_COMPMISMATCH (1 << 6)
|
||||
#define DF_STATUS_SECTORPROTECTION_ON (1 << 1)
|
||||
//@}
|
||||
|
||||
#define DF_MANUFACTURER_ATMEL 0x1F
|
||||
|
||||
/** \name Dataflash Commands */
|
||||
//@{
|
||||
#define DF_CMD_GETSTATUS 0xD7
|
||||
|
||||
#define DF_CMD_MAINMEMTOBUFF1 0x53
|
||||
#define DF_CMD_MAINMEMTOBUFF2 0x55
|
||||
#define DF_CMD_MAINMEMTOBUFF1COMP 0x60
|
||||
#define DF_CMD_MAINMEMTOBUFF2COMP 0x61
|
||||
#define DF_CMD_AUTOREWRITEBUFF1 0x58
|
||||
#define DF_CMD_AUTOREWRITEBUFF2 0x59
|
||||
|
||||
#define DF_CMD_MAINMEMPAGEREAD 0xD2
|
||||
#define DF_CMD_CONTARRAYREAD_LF 0xE8
|
||||
#define DF_CMD_BUFF1READ_LF 0xD4
|
||||
#define DF_CMD_BUFF2READ_LF 0xD6
|
||||
|
||||
#define DF_CMD_BUFF1WRITE 0x84
|
||||
#define DF_CMD_BUFF2WRITE 0x87
|
||||
#define DF_CMD_BUFF1TOMAINMEMWITHERASE 0x83
|
||||
#define DF_CMD_BUFF2TOMAINMEMWITHERASE 0x86
|
||||
#define DF_CMD_BUFF1TOMAINMEM 0x88
|
||||
#define DF_CMD_BUFF2TOMAINMEM 0x89
|
||||
#define DF_CMD_MAINMEMPAGETHROUGHBUFF1 0x82
|
||||
#define DF_CMD_MAINMEMPAGETHROUGHBUFF2 0x85
|
||||
|
||||
#define DF_CMD_PAGEERASE 0x81
|
||||
#define DF_CMD_BLOCKERASE 0x50
|
||||
|
||||
#define DF_CMD_SECTORPROTECTIONOFF ((char[]){0x3D, 0x2A, 0x7F, 0xCF})
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE1 0x3D
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE2 0x2A
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE3 0x7F
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE4 0xCF
|
||||
|
||||
#define DF_CMD_READMANUFACTURERDEVICEINFO 0x9F
|
||||
//@}
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Command constants for the Atmel AT45DB642D Dataflash.
|
||||
* \copydetails Group_AT45DB642D
|
||||
*/
|
||||
|
||||
/** \ingroup Group_MiscDrivers
|
||||
* \defgroup Group_AT45DB642D Atmel AT45DB642D Dataflash Commands
|
||||
* \brief Command constants for the Atmel AT45DB642D Dataflash.
|
||||
*
|
||||
* Dataflash command constants for the Atmel AT45DB642D Dataflash IC.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __AT45DB642D_CMDS_H__
|
||||
#define __AT45DB642D_CMDS_H__
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name Dataflash Status Values */
|
||||
//@{
|
||||
#define DF_STATUS_READY (1 << 7)
|
||||
#define DF_STATUS_COMPMISMATCH (1 << 6)
|
||||
#define DF_STATUS_SECTORPROTECTION_ON (1 << 1)
|
||||
#define DF_STATUS_BINARYPAGESIZE_ON (1 << 0)
|
||||
//@}
|
||||
|
||||
#define DF_MANUFACTURER_ATMEL 0x1F
|
||||
|
||||
/** \name Dataflash Commands */
|
||||
//@{
|
||||
#define DF_CMD_GETSTATUS 0xD7
|
||||
#define DF_CMD_POWERDOWN 0xB9
|
||||
#define DF_CMD_WAKEUP 0xAB
|
||||
|
||||
#define DF_CMD_MAINMEMTOBUFF1 0x53
|
||||
#define DF_CMD_MAINMEMTOBUFF2 0x55
|
||||
#define DF_CMD_MAINMEMTOBUFF1COMP 0x60
|
||||
#define DF_CMD_MAINMEMTOBUFF2COMP 0x61
|
||||
#define DF_CMD_AUTOREWRITEBUFF1 0x58
|
||||
#define DF_CMD_AUTOREWRITEBUFF2 0x59
|
||||
|
||||
#define DF_CMD_MAINMEMPAGEREAD 0xD2
|
||||
#define DF_CMD_CONTARRAYREAD_LF 0x03
|
||||
#define DF_CMD_BUFF1READ_LF 0xD1
|
||||
#define DF_CMD_BUFF2READ_LF 0xD3
|
||||
|
||||
#define DF_CMD_BUFF1WRITE 0x84
|
||||
#define DF_CMD_BUFF2WRITE 0x87
|
||||
#define DF_CMD_BUFF1TOMAINMEMWITHERASE 0x83
|
||||
#define DF_CMD_BUFF2TOMAINMEMWITHERASE 0x86
|
||||
#define DF_CMD_BUFF1TOMAINMEM 0x88
|
||||
#define DF_CMD_BUFF2TOMAINMEM 0x89
|
||||
#define DF_CMD_MAINMEMPAGETHROUGHBUFF1 0x82
|
||||
#define DF_CMD_MAINMEMPAGETHROUGHBUFF2 0x85
|
||||
|
||||
#define DF_CMD_PAGEERASE 0x81
|
||||
#define DF_CMD_BLOCKERASE 0x50
|
||||
#define DF_CMD_SECTORERASE 0x7C
|
||||
|
||||
#define DF_CMD_CHIPERASE ((char[]){0xC7, 0x94, 0x80, 0x9A})
|
||||
#define DF_CMD_CHIPERASE_BYTE1 0xC7
|
||||
#define DF_CMD_CHIPERASE_BYTE2 0x94
|
||||
#define DF_CMD_CHIPERASE_BYTE3 0x80
|
||||
#define DF_CMD_CHIPERASE_BYTE4 0x9A
|
||||
|
||||
#define DF_CMD_SECTORPROTECTIONOFF ((char[]){0x3D, 0x2A, 0x7F, 0x9A})
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE1 0x3D
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE2 0x2A
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE3 0x7F
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE4 0x9A
|
||||
|
||||
#define DF_CMD_READMANUFACTURERDEVICEINFO 0x9F
|
||||
//@}
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Command constants for the Atmel AT45DB642D Dataflash.
|
||||
* \copydetails Group_AT45DB642D
|
||||
*/
|
||||
|
||||
/** \ingroup Group_MiscDrivers
|
||||
* \defgroup Group_AT45DB642D Atmel AT45DB642D Dataflash Commands
|
||||
* \brief Command constants for the Atmel AT45DB642D Dataflash.
|
||||
*
|
||||
* Dataflash command constants for the Atmel AT45DB642D Dataflash IC.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __AT45DB642D_CMDS_H__
|
||||
#define __AT45DB642D_CMDS_H__
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name Dataflash Status Values */
|
||||
//@{
|
||||
#define DF_STATUS_READY (1 << 7)
|
||||
#define DF_STATUS_COMPMISMATCH (1 << 6)
|
||||
#define DF_STATUS_SECTORPROTECTION_ON (1 << 1)
|
||||
#define DF_STATUS_BINARYPAGESIZE_ON (1 << 0)
|
||||
//@}
|
||||
|
||||
#define DF_MANUFACTURER_ATMEL 0x1F
|
||||
|
||||
/** \name Dataflash Commands */
|
||||
//@{
|
||||
#define DF_CMD_GETSTATUS 0xD7
|
||||
#define DF_CMD_POWERDOWN 0xB9
|
||||
#define DF_CMD_WAKEUP 0xAB
|
||||
|
||||
#define DF_CMD_MAINMEMTOBUFF1 0x53
|
||||
#define DF_CMD_MAINMEMTOBUFF2 0x55
|
||||
#define DF_CMD_MAINMEMTOBUFF1COMP 0x60
|
||||
#define DF_CMD_MAINMEMTOBUFF2COMP 0x61
|
||||
#define DF_CMD_AUTOREWRITEBUFF1 0x58
|
||||
#define DF_CMD_AUTOREWRITEBUFF2 0x59
|
||||
|
||||
#define DF_CMD_MAINMEMPAGEREAD 0xD2
|
||||
#define DF_CMD_CONTARRAYREAD_LF 0x03
|
||||
#define DF_CMD_BUFF1READ_LF 0xD1
|
||||
#define DF_CMD_BUFF2READ_LF 0xD3
|
||||
|
||||
#define DF_CMD_BUFF1WRITE 0x84
|
||||
#define DF_CMD_BUFF2WRITE 0x87
|
||||
#define DF_CMD_BUFF1TOMAINMEMWITHERASE 0x83
|
||||
#define DF_CMD_BUFF2TOMAINMEMWITHERASE 0x86
|
||||
#define DF_CMD_BUFF1TOMAINMEM 0x88
|
||||
#define DF_CMD_BUFF2TOMAINMEM 0x89
|
||||
#define DF_CMD_MAINMEMPAGETHROUGHBUFF1 0x82
|
||||
#define DF_CMD_MAINMEMPAGETHROUGHBUFF2 0x85
|
||||
|
||||
#define DF_CMD_PAGEERASE 0x81
|
||||
#define DF_CMD_BLOCKERASE 0x50
|
||||
#define DF_CMD_SECTORERASE 0x7C
|
||||
|
||||
#define DF_CMD_CHIPERASE ((char[]){0xC7, 0x94, 0x80, 0x9A})
|
||||
#define DF_CMD_CHIPERASE_BYTE1 0xC7
|
||||
#define DF_CMD_CHIPERASE_BYTE2 0x94
|
||||
#define DF_CMD_CHIPERASE_BYTE3 0x80
|
||||
#define DF_CMD_CHIPERASE_BYTE4 0x9A
|
||||
|
||||
#define DF_CMD_SECTORPROTECTIONOFF ((char[]){0x3D, 0x2A, 0x7F, 0x9A})
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE1 0x3D
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE2 0x2A
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE3 0x7F
|
||||
#define DF_CMD_SECTORPROTECTIONOFF_BYTE4 0x9A
|
||||
|
||||
#define DF_CMD_READMANUFACTURERDEVICEINFO 0x9F
|
||||
//@}
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,303 +1,303 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Lightweight ring (circular) buffer, for fast insertion/deletion of bytes.
|
||||
*
|
||||
* Lightweight ring buffer, for fast insertion/deletion. Multiple buffers can be created of
|
||||
* different sizes to suit different needs.
|
||||
*
|
||||
* Note that for each buffer, insertion and removal operations may occur at the same time (via
|
||||
* a multi-threaded ISR based system) however the same kind of operation (two or more insertions
|
||||
* or deletions) must not overlap. If there is possibility of two or more of the same kind of
|
||||
* operating occurring at the same point in time, atomic (mutex) locking should be used.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_MiscDrivers
|
||||
* \defgroup Group_RingBuff Generic Byte Ring Buffer - LUFA/Drivers/Misc/RingBuffer.h
|
||||
* \brief Lightweight ring buffer, for fast insertion/deletion of bytes.
|
||||
*
|
||||
* \section Sec_Dependencies Module Source Dependencies
|
||||
* The following files must be built with any user project that uses this module:
|
||||
* - None
|
||||
*
|
||||
* \section Sec_ModDescription Module Description
|
||||
* Lightweight ring buffer, for fast insertion/deletion. Multiple buffers can be created of
|
||||
* different sizes to suit different needs.
|
||||
*
|
||||
* Note that for each buffer, insertion and removal operations may occur at the same time (via
|
||||
* a multi-threaded ISR based system) however the same kind of operation (two or more insertions
|
||||
* or deletions) must not overlap. If there is possibility of two or more of the same kind of
|
||||
* operating occurring at the same point in time, atomic (mutex) locking should be used.
|
||||
*
|
||||
* \section Sec_ExampleUsage Example Usage
|
||||
* The following snippet is an example of how this module may be used within a typical
|
||||
* application.
|
||||
*
|
||||
* \code
|
||||
* // Create the buffer structure and its underlying storage array
|
||||
* RingBuffer_t Buffer;
|
||||
* uint8_t BufferData[128];
|
||||
*
|
||||
* // Initialize the buffer with the created storage array
|
||||
* RingBuffer_InitBuffer(&Buffer, BufferData, sizeof(BufferData));
|
||||
*
|
||||
* // Insert some data into the buffer
|
||||
* RingBuffer_Insert(Buffer, 'H');
|
||||
* RingBuffer_Insert(Buffer, 'E');
|
||||
* RingBuffer_Insert(Buffer, 'L');
|
||||
* RingBuffer_Insert(Buffer, 'L');
|
||||
* RingBuffer_Insert(Buffer, 'O');
|
||||
*
|
||||
* // Cache the number of stored bytes in the buffer
|
||||
* uint16_t BufferCount = RingBuffer_GetCount(&Buffer);
|
||||
*
|
||||
* // Printer stored data length
|
||||
* printf("Buffer Length: %d, Buffer Data: \r\n", BufferCount);
|
||||
*
|
||||
* // Print contents of the buffer one character at a time
|
||||
* while (BufferCount--)
|
||||
* putc(RingBuffer_Remove(&Buffer));
|
||||
* \endcode
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __RING_BUFFER_H__
|
||||
#define __RING_BUFFER_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Type Defines: */
|
||||
/** \brief Ring Buffer Management Structure.
|
||||
*
|
||||
* Type define for a new ring buffer object. Buffers should be initialized via a call to
|
||||
* \ref RingBuffer_InitBuffer() before use.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t* In; /**< Current storage location in the circular buffer. */
|
||||
uint8_t* Out; /**< Current retrieval location in the circular buffer. */
|
||||
uint8_t* Start; /**< Pointer to the start of the buffer's underlying storage array. */
|
||||
uint8_t* End; /**< Pointer to the end of the buffer's underlying storage array. */
|
||||
uint8_t Size; /**< Size of the buffer's underlying storage array. */
|
||||
uint16_t Count; /**< Number of bytes currently stored in the buffer. */
|
||||
} RingBuffer_t;
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Initializes a ring buffer ready for use. Buffers must be initialized via this function
|
||||
* before any operations are called upon them. Already initialized buffers may be reset
|
||||
* by re-initializing them using this function.
|
||||
*
|
||||
* \param[out] Buffer Pointer to a ring buffer structure to initialize.
|
||||
* \param[out] DataPtr Pointer to a global array that will hold the data stored into the ring buffer.
|
||||
* \param[out] Size Maximum number of bytes that can be stored in the underlying data array.
|
||||
*/
|
||||
static inline void RingBuffer_InitBuffer(RingBuffer_t* Buffer, uint8_t* const DataPtr, const uint16_t Size)
|
||||
ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
|
||||
static inline void RingBuffer_InitBuffer(RingBuffer_t* Buffer, uint8_t* const DataPtr, const uint16_t Size)
|
||||
{
|
||||
GCC_FORCE_POINTER_ACCESS(Buffer);
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
Buffer->In = DataPtr;
|
||||
Buffer->Out = DataPtr;
|
||||
Buffer->Start = &DataPtr[0];
|
||||
Buffer->End = &DataPtr[Size];
|
||||
Buffer->Size = Size;
|
||||
Buffer->Count = 0;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
}
|
||||
|
||||
/** Retrieves the current number of bytes stored in a particular buffer. This value is computed
|
||||
* by entering an atomic lock on the buffer, so that the buffer cannot be modified while the
|
||||
* computation takes place. This value should be cached when reading out the contents of the buffer,
|
||||
* so that as small a time as possible is spent in an atomic lock.
|
||||
*
|
||||
* \note The value returned by this function is guaranteed to only be the minimum number of bytes
|
||||
* stored in the given buffer; this value may change as other threads write new data, thus
|
||||
* the returned number should be used only to determine how many successive reads may safely
|
||||
* be performed on the buffer.
|
||||
*
|
||||
* \param[in] Buffer Pointer to a ring buffer structure whose count is to be computed.
|
||||
*
|
||||
* \return Number of bytes currently stored in the buffer.
|
||||
*/
|
||||
static inline uint16_t RingBuffer_GetCount(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline uint16_t RingBuffer_GetCount(RingBuffer_t* const Buffer)
|
||||
{
|
||||
uint16_t Count;
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
Count = Buffer->Count;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
return Count;
|
||||
}
|
||||
|
||||
/** Retrieves the free space in a particular buffer. This value is computed by entering an atomic lock
|
||||
* on the buffer, so that the buffer cannot be modified while the computation takes place.
|
||||
*
|
||||
* \note The value returned by this function is guaranteed to only be the maximum number of bytes
|
||||
* free in the given buffer; this value may change as other threads write new data, thus
|
||||
* the returned number should be used only to determine how many successive writes may safely
|
||||
* be performed on the buffer when there is a single writer thread.
|
||||
*
|
||||
* \param[in] Buffer Pointer to a ring buffer structure whose free count is to be computed.
|
||||
*
|
||||
* \return Number of free bytes in the buffer.
|
||||
*/
|
||||
static inline uint16_t RingBuffer_GetFreeCount(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline uint16_t RingBuffer_GetFreeCount(RingBuffer_t* const Buffer)
|
||||
{
|
||||
return (Buffer->Size - RingBuffer_GetCount(Buffer));
|
||||
}
|
||||
|
||||
/** Atomically determines if the specified ring buffer contains any data. This should
|
||||
* be tested before removing data from the buffer, to ensure that the buffer does not
|
||||
* underflow.
|
||||
*
|
||||
* If the data is to be removed in a loop, store the total number of bytes stored in the
|
||||
* buffer (via a call to the \ref RingBuffer_GetCount() function) in a temporary variable
|
||||
* to reduce the time spent in atomicity locks.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to insert into.
|
||||
*
|
||||
* \return Boolean \c true if the buffer contains no free space, false otherwise.
|
||||
*/
|
||||
static inline bool RingBuffer_IsEmpty(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline bool RingBuffer_IsEmpty(RingBuffer_t* const Buffer)
|
||||
{
|
||||
return (RingBuffer_GetCount(Buffer) == 0);
|
||||
}
|
||||
|
||||
/** Atomically determines if the specified ring buffer contains any free space. This should
|
||||
* be tested before storing data to the buffer, to ensure that no data is lost due to a
|
||||
* buffer overrun.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to insert into.
|
||||
*
|
||||
* \return Boolean \c true if the buffer contains no free space, false otherwise.
|
||||
*/
|
||||
static inline bool RingBuffer_IsFull(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline bool RingBuffer_IsFull(RingBuffer_t* const Buffer)
|
||||
{
|
||||
return (RingBuffer_GetCount(Buffer) == Buffer->Size);
|
||||
}
|
||||
|
||||
/** Inserts an element into the ring buffer.
|
||||
*
|
||||
* \note Only one execution thread (main program thread or an ISR) may insert into a single buffer
|
||||
* otherwise data corruption may occur. Insertion and removal may occur from different execution
|
||||
* threads.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to insert into.
|
||||
* \param[in] Data Data element to insert into the buffer.
|
||||
*/
|
||||
static inline void RingBuffer_Insert(RingBuffer_t* Buffer, const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline void RingBuffer_Insert(RingBuffer_t* Buffer, const uint8_t Data)
|
||||
{
|
||||
GCC_FORCE_POINTER_ACCESS(Buffer);
|
||||
|
||||
*Buffer->In = Data;
|
||||
|
||||
if (++Buffer->In == Buffer->End)
|
||||
Buffer->In = Buffer->Start;
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
Buffer->Count++;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
}
|
||||
|
||||
/** Removes an element from the ring buffer.
|
||||
*
|
||||
* \note Only one execution thread (main program thread or an ISR) may remove from a single buffer
|
||||
* otherwise data corruption may occur. Insertion and removal may occur from different execution
|
||||
* threads.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to retrieve from.
|
||||
*
|
||||
* \return Next data element stored in the buffer.
|
||||
*/
|
||||
static inline uint8_t RingBuffer_Remove(RingBuffer_t* Buffer) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline uint8_t RingBuffer_Remove(RingBuffer_t* Buffer)
|
||||
{
|
||||
GCC_FORCE_POINTER_ACCESS(Buffer);
|
||||
|
||||
uint8_t Data = *Buffer->Out;
|
||||
|
||||
if (++Buffer->Out == Buffer->End)
|
||||
Buffer->Out = Buffer->Start;
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
Buffer->Count--;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
|
||||
return Data;
|
||||
}
|
||||
|
||||
/** Returns the next element stored in the ring buffer, without removing it.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to retrieve from.
|
||||
*
|
||||
* \return Next data element stored in the buffer.
|
||||
*/
|
||||
static inline uint8_t RingBuffer_Peek(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline uint8_t RingBuffer_Peek(RingBuffer_t* const Buffer)
|
||||
{
|
||||
return *Buffer->Out;
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Lightweight ring (circular) buffer, for fast insertion/deletion of bytes.
|
||||
*
|
||||
* Lightweight ring buffer, for fast insertion/deletion. Multiple buffers can be created of
|
||||
* different sizes to suit different needs.
|
||||
*
|
||||
* Note that for each buffer, insertion and removal operations may occur at the same time (via
|
||||
* a multi-threaded ISR based system) however the same kind of operation (two or more insertions
|
||||
* or deletions) must not overlap. If there is possibility of two or more of the same kind of
|
||||
* operating occurring at the same point in time, atomic (mutex) locking should be used.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_MiscDrivers
|
||||
* \defgroup Group_RingBuff Generic Byte Ring Buffer - LUFA/Drivers/Misc/RingBuffer.h
|
||||
* \brief Lightweight ring buffer, for fast insertion/deletion of bytes.
|
||||
*
|
||||
* \section Sec_Dependencies Module Source Dependencies
|
||||
* The following files must be built with any user project that uses this module:
|
||||
* - None
|
||||
*
|
||||
* \section Sec_ModDescription Module Description
|
||||
* Lightweight ring buffer, for fast insertion/deletion. Multiple buffers can be created of
|
||||
* different sizes to suit different needs.
|
||||
*
|
||||
* Note that for each buffer, insertion and removal operations may occur at the same time (via
|
||||
* a multi-threaded ISR based system) however the same kind of operation (two or more insertions
|
||||
* or deletions) must not overlap. If there is possibility of two or more of the same kind of
|
||||
* operating occurring at the same point in time, atomic (mutex) locking should be used.
|
||||
*
|
||||
* \section Sec_ExampleUsage Example Usage
|
||||
* The following snippet is an example of how this module may be used within a typical
|
||||
* application.
|
||||
*
|
||||
* \code
|
||||
* // Create the buffer structure and its underlying storage array
|
||||
* RingBuffer_t Buffer;
|
||||
* uint8_t BufferData[128];
|
||||
*
|
||||
* // Initialize the buffer with the created storage array
|
||||
* RingBuffer_InitBuffer(&Buffer, BufferData, sizeof(BufferData));
|
||||
*
|
||||
* // Insert some data into the buffer
|
||||
* RingBuffer_Insert(Buffer, 'H');
|
||||
* RingBuffer_Insert(Buffer, 'E');
|
||||
* RingBuffer_Insert(Buffer, 'L');
|
||||
* RingBuffer_Insert(Buffer, 'L');
|
||||
* RingBuffer_Insert(Buffer, 'O');
|
||||
*
|
||||
* // Cache the number of stored bytes in the buffer
|
||||
* uint16_t BufferCount = RingBuffer_GetCount(&Buffer);
|
||||
*
|
||||
* // Printer stored data length
|
||||
* printf("Buffer Length: %d, Buffer Data: \r\n", BufferCount);
|
||||
*
|
||||
* // Print contents of the buffer one character at a time
|
||||
* while (BufferCount--)
|
||||
* putc(RingBuffer_Remove(&Buffer));
|
||||
* \endcode
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __RING_BUFFER_H__
|
||||
#define __RING_BUFFER_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Type Defines: */
|
||||
/** \brief Ring Buffer Management Structure.
|
||||
*
|
||||
* Type define for a new ring buffer object. Buffers should be initialized via a call to
|
||||
* \ref RingBuffer_InitBuffer() before use.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t* In; /**< Current storage location in the circular buffer. */
|
||||
uint8_t* Out; /**< Current retrieval location in the circular buffer. */
|
||||
uint8_t* Start; /**< Pointer to the start of the buffer's underlying storage array. */
|
||||
uint8_t* End; /**< Pointer to the end of the buffer's underlying storage array. */
|
||||
uint8_t Size; /**< Size of the buffer's underlying storage array. */
|
||||
uint16_t Count; /**< Number of bytes currently stored in the buffer. */
|
||||
} RingBuffer_t;
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Initializes a ring buffer ready for use. Buffers must be initialized via this function
|
||||
* before any operations are called upon them. Already initialized buffers may be reset
|
||||
* by re-initializing them using this function.
|
||||
*
|
||||
* \param[out] Buffer Pointer to a ring buffer structure to initialize.
|
||||
* \param[out] DataPtr Pointer to a global array that will hold the data stored into the ring buffer.
|
||||
* \param[out] Size Maximum number of bytes that can be stored in the underlying data array.
|
||||
*/
|
||||
static inline void RingBuffer_InitBuffer(RingBuffer_t* Buffer, uint8_t* const DataPtr, const uint16_t Size)
|
||||
ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
|
||||
static inline void RingBuffer_InitBuffer(RingBuffer_t* Buffer, uint8_t* const DataPtr, const uint16_t Size)
|
||||
{
|
||||
GCC_FORCE_POINTER_ACCESS(Buffer);
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
Buffer->In = DataPtr;
|
||||
Buffer->Out = DataPtr;
|
||||
Buffer->Start = &DataPtr[0];
|
||||
Buffer->End = &DataPtr[Size];
|
||||
Buffer->Size = Size;
|
||||
Buffer->Count = 0;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
}
|
||||
|
||||
/** Retrieves the current number of bytes stored in a particular buffer. This value is computed
|
||||
* by entering an atomic lock on the buffer, so that the buffer cannot be modified while the
|
||||
* computation takes place. This value should be cached when reading out the contents of the buffer,
|
||||
* so that as small a time as possible is spent in an atomic lock.
|
||||
*
|
||||
* \note The value returned by this function is guaranteed to only be the minimum number of bytes
|
||||
* stored in the given buffer; this value may change as other threads write new data, thus
|
||||
* the returned number should be used only to determine how many successive reads may safely
|
||||
* be performed on the buffer.
|
||||
*
|
||||
* \param[in] Buffer Pointer to a ring buffer structure whose count is to be computed.
|
||||
*
|
||||
* \return Number of bytes currently stored in the buffer.
|
||||
*/
|
||||
static inline uint16_t RingBuffer_GetCount(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline uint16_t RingBuffer_GetCount(RingBuffer_t* const Buffer)
|
||||
{
|
||||
uint16_t Count;
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
Count = Buffer->Count;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
return Count;
|
||||
}
|
||||
|
||||
/** Retrieves the free space in a particular buffer. This value is computed by entering an atomic lock
|
||||
* on the buffer, so that the buffer cannot be modified while the computation takes place.
|
||||
*
|
||||
* \note The value returned by this function is guaranteed to only be the maximum number of bytes
|
||||
* free in the given buffer; this value may change as other threads write new data, thus
|
||||
* the returned number should be used only to determine how many successive writes may safely
|
||||
* be performed on the buffer when there is a single writer thread.
|
||||
*
|
||||
* \param[in] Buffer Pointer to a ring buffer structure whose free count is to be computed.
|
||||
*
|
||||
* \return Number of free bytes in the buffer.
|
||||
*/
|
||||
static inline uint16_t RingBuffer_GetFreeCount(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline uint16_t RingBuffer_GetFreeCount(RingBuffer_t* const Buffer)
|
||||
{
|
||||
return (Buffer->Size - RingBuffer_GetCount(Buffer));
|
||||
}
|
||||
|
||||
/** Atomically determines if the specified ring buffer contains any data. This should
|
||||
* be tested before removing data from the buffer, to ensure that the buffer does not
|
||||
* underflow.
|
||||
*
|
||||
* If the data is to be removed in a loop, store the total number of bytes stored in the
|
||||
* buffer (via a call to the \ref RingBuffer_GetCount() function) in a temporary variable
|
||||
* to reduce the time spent in atomicity locks.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to insert into.
|
||||
*
|
||||
* \return Boolean \c true if the buffer contains no free space, false otherwise.
|
||||
*/
|
||||
static inline bool RingBuffer_IsEmpty(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline bool RingBuffer_IsEmpty(RingBuffer_t* const Buffer)
|
||||
{
|
||||
return (RingBuffer_GetCount(Buffer) == 0);
|
||||
}
|
||||
|
||||
/** Atomically determines if the specified ring buffer contains any free space. This should
|
||||
* be tested before storing data to the buffer, to ensure that no data is lost due to a
|
||||
* buffer overrun.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to insert into.
|
||||
*
|
||||
* \return Boolean \c true if the buffer contains no free space, false otherwise.
|
||||
*/
|
||||
static inline bool RingBuffer_IsFull(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline bool RingBuffer_IsFull(RingBuffer_t* const Buffer)
|
||||
{
|
||||
return (RingBuffer_GetCount(Buffer) == Buffer->Size);
|
||||
}
|
||||
|
||||
/** Inserts an element into the ring buffer.
|
||||
*
|
||||
* \note Only one execution thread (main program thread or an ISR) may insert into a single buffer
|
||||
* otherwise data corruption may occur. Insertion and removal may occur from different execution
|
||||
* threads.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to insert into.
|
||||
* \param[in] Data Data element to insert into the buffer.
|
||||
*/
|
||||
static inline void RingBuffer_Insert(RingBuffer_t* Buffer, const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline void RingBuffer_Insert(RingBuffer_t* Buffer, const uint8_t Data)
|
||||
{
|
||||
GCC_FORCE_POINTER_ACCESS(Buffer);
|
||||
|
||||
*Buffer->In = Data;
|
||||
|
||||
if (++Buffer->In == Buffer->End)
|
||||
Buffer->In = Buffer->Start;
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
Buffer->Count++;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
}
|
||||
|
||||
/** Removes an element from the ring buffer.
|
||||
*
|
||||
* \note Only one execution thread (main program thread or an ISR) may remove from a single buffer
|
||||
* otherwise data corruption may occur. Insertion and removal may occur from different execution
|
||||
* threads.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to retrieve from.
|
||||
*
|
||||
* \return Next data element stored in the buffer.
|
||||
*/
|
||||
static inline uint8_t RingBuffer_Remove(RingBuffer_t* Buffer) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline uint8_t RingBuffer_Remove(RingBuffer_t* Buffer)
|
||||
{
|
||||
GCC_FORCE_POINTER_ACCESS(Buffer);
|
||||
|
||||
uint8_t Data = *Buffer->Out;
|
||||
|
||||
if (++Buffer->Out == Buffer->End)
|
||||
Buffer->Out = Buffer->Start;
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
Buffer->Count--;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
|
||||
return Data;
|
||||
}
|
||||
|
||||
/** Returns the next element stored in the ring buffer, without removing it.
|
||||
*
|
||||
* \param[in,out] Buffer Pointer to a ring buffer structure to retrieve from.
|
||||
*
|
||||
* \return Next data element stored in the buffer.
|
||||
*/
|
||||
static inline uint8_t RingBuffer_Peek(RingBuffer_t* const Buffer) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline uint8_t RingBuffer_Peek(RingBuffer_t* const Buffer)
|
||||
{
|
||||
return *Buffer->Out;
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,159 +1,159 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB Device definitions for all architectures.
|
||||
* \copydetails Group_Device
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_Device Device Management
|
||||
* \brief USB Device management definitions for USB device mode.
|
||||
*
|
||||
* USB Device mode related definitions common to all architectures. This module contains definitions which
|
||||
* are used when the USB controller is initialized in device mode.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBDEVICE_H__
|
||||
#define __USBDEVICE_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
#include "StdDescriptors.h"
|
||||
#include "USBInterrupt.h"
|
||||
#include "Endpoint.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for the various states of the USB Device state machine. Only some states are
|
||||
* implemented in the LUFA library - other states are left to the user to implement.
|
||||
*
|
||||
* For information on each possible USB device state, refer to the USB 2.0 specification.
|
||||
*
|
||||
* \see \ref USB_DeviceState, which stores the current device state machine state.
|
||||
*/
|
||||
enum USB_Device_States_t
|
||||
{
|
||||
DEVICE_STATE_Unattached = 0, /**< Internally implemented by the library. This state indicates
|
||||
* that the device is not currently connected to a host.
|
||||
*/
|
||||
DEVICE_STATE_Powered = 1, /**< Internally implemented by the library. This state indicates
|
||||
* that the device is connected to a host, but enumeration has not
|
||||
* yet begun.
|
||||
*/
|
||||
DEVICE_STATE_Default = 2, /**< Internally implemented by the library. This state indicates
|
||||
* that the device's USB bus has been reset by the host and it is
|
||||
* now waiting for the host to begin the enumeration process.
|
||||
*/
|
||||
DEVICE_STATE_Addressed = 3, /**< Internally implemented by the library. This state indicates
|
||||
* that the device has been addressed by the USB Host, but is not
|
||||
* yet configured.
|
||||
*/
|
||||
DEVICE_STATE_Configured = 4, /**< May be implemented by the user project. This state indicates
|
||||
* that the device has been enumerated by the host and is ready
|
||||
* for USB communications to begin.
|
||||
*/
|
||||
DEVICE_STATE_Suspended = 5, /**< May be implemented by the user project. This state indicates
|
||||
* that the USB bus has been suspended by the host, and the device
|
||||
* should power down to a minimal power level until the bus is
|
||||
* resumed.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Function to retrieve a given descriptor's size and memory location from the given descriptor type value,
|
||||
* index and language ID. This function MUST be overridden in the user application (added with full, identical
|
||||
* prototype and name so that the library can call it to retrieve descriptor data.
|
||||
*
|
||||
* \param[in] wValue The type of the descriptor to retrieve in the upper byte, and the index in the
|
||||
* lower byte (when more than one descriptor of the given type exists, such as the
|
||||
* case of string descriptors). The type may be one of the standard types defined
|
||||
* in the DescriptorTypes_t enum, or may be a class-specific descriptor type value.
|
||||
* \param[in] wIndex The language ID of the string to return if the \c wValue type indicates
|
||||
* \ref DTYPE_String, otherwise zero for standard descriptors, or as defined in a
|
||||
* class-specific standards.
|
||||
* \param[out] DescriptorAddress Pointer to the descriptor in memory. This should be set by the routine to
|
||||
* the address of the descriptor.
|
||||
* \param[out] MemoryAddressSpace A value from the \ref USB_DescriptorMemorySpaces_t enum to indicate the memory
|
||||
* space in which the descriptor is stored. This parameter does not exist when one
|
||||
* of the \c USE_*_DESCRIPTORS compile time options is used, or on architectures which
|
||||
* use a unified address space.
|
||||
*
|
||||
* \note By default, the library expects all descriptors to be located in flash memory via the \c PROGMEM attribute.
|
||||
* If descriptors should be located in RAM or EEPROM instead (to speed up access in the case of RAM, or to
|
||||
* allow the descriptors to be changed dynamically at runtime) either the \c USE_RAM_DESCRIPTORS or the
|
||||
* \c USE_EEPROM_DESCRIPTORS tokens may be defined in the project makefile and passed to the compiler by the -D
|
||||
* switch.
|
||||
*
|
||||
* \return Size in bytes of the descriptor if it exists, zero or \ref NO_DESCRIPTOR otherwise.
|
||||
*/
|
||||
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
||||
const uint8_t wIndex,
|
||||
const void** const DescriptorAddress
|
||||
#if (defined(ARCH_HAS_MULTI_ADDRESS_SPACE) || defined(__DOXYGEN__)) && \
|
||||
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
|
||||
, uint8_t* MemoryAddressSpace
|
||||
#endif
|
||||
) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/Device_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/Device_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/Device_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB Device definitions for all architectures.
|
||||
* \copydetails Group_Device
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_Device Device Management
|
||||
* \brief USB Device management definitions for USB device mode.
|
||||
*
|
||||
* USB Device mode related definitions common to all architectures. This module contains definitions which
|
||||
* are used when the USB controller is initialized in device mode.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBDEVICE_H__
|
||||
#define __USBDEVICE_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
#include "StdDescriptors.h"
|
||||
#include "USBInterrupt.h"
|
||||
#include "Endpoint.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for the various states of the USB Device state machine. Only some states are
|
||||
* implemented in the LUFA library - other states are left to the user to implement.
|
||||
*
|
||||
* For information on each possible USB device state, refer to the USB 2.0 specification.
|
||||
*
|
||||
* \see \ref USB_DeviceState, which stores the current device state machine state.
|
||||
*/
|
||||
enum USB_Device_States_t
|
||||
{
|
||||
DEVICE_STATE_Unattached = 0, /**< Internally implemented by the library. This state indicates
|
||||
* that the device is not currently connected to a host.
|
||||
*/
|
||||
DEVICE_STATE_Powered = 1, /**< Internally implemented by the library. This state indicates
|
||||
* that the device is connected to a host, but enumeration has not
|
||||
* yet begun.
|
||||
*/
|
||||
DEVICE_STATE_Default = 2, /**< Internally implemented by the library. This state indicates
|
||||
* that the device's USB bus has been reset by the host and it is
|
||||
* now waiting for the host to begin the enumeration process.
|
||||
*/
|
||||
DEVICE_STATE_Addressed = 3, /**< Internally implemented by the library. This state indicates
|
||||
* that the device has been addressed by the USB Host, but is not
|
||||
* yet configured.
|
||||
*/
|
||||
DEVICE_STATE_Configured = 4, /**< May be implemented by the user project. This state indicates
|
||||
* that the device has been enumerated by the host and is ready
|
||||
* for USB communications to begin.
|
||||
*/
|
||||
DEVICE_STATE_Suspended = 5, /**< May be implemented by the user project. This state indicates
|
||||
* that the USB bus has been suspended by the host, and the device
|
||||
* should power down to a minimal power level until the bus is
|
||||
* resumed.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Function to retrieve a given descriptor's size and memory location from the given descriptor type value,
|
||||
* index and language ID. This function MUST be overridden in the user application (added with full, identical
|
||||
* prototype and name so that the library can call it to retrieve descriptor data.
|
||||
*
|
||||
* \param[in] wValue The type of the descriptor to retrieve in the upper byte, and the index in the
|
||||
* lower byte (when more than one descriptor of the given type exists, such as the
|
||||
* case of string descriptors). The type may be one of the standard types defined
|
||||
* in the DescriptorTypes_t enum, or may be a class-specific descriptor type value.
|
||||
* \param[in] wIndex The language ID of the string to return if the \c wValue type indicates
|
||||
* \ref DTYPE_String, otherwise zero for standard descriptors, or as defined in a
|
||||
* class-specific standards.
|
||||
* \param[out] DescriptorAddress Pointer to the descriptor in memory. This should be set by the routine to
|
||||
* the address of the descriptor.
|
||||
* \param[out] MemoryAddressSpace A value from the \ref USB_DescriptorMemorySpaces_t enum to indicate the memory
|
||||
* space in which the descriptor is stored. This parameter does not exist when one
|
||||
* of the \c USE_*_DESCRIPTORS compile time options is used, or on architectures which
|
||||
* use a unified address space.
|
||||
*
|
||||
* \note By default, the library expects all descriptors to be located in flash memory via the \c PROGMEM attribute.
|
||||
* If descriptors should be located in RAM or EEPROM instead (to speed up access in the case of RAM, or to
|
||||
* allow the descriptors to be changed dynamically at runtime) either the \c USE_RAM_DESCRIPTORS or the
|
||||
* \c USE_EEPROM_DESCRIPTORS tokens may be defined in the project makefile and passed to the compiler by the -D
|
||||
* switch.
|
||||
*
|
||||
* \return Size in bytes of the descriptor if it exists, zero or \ref NO_DESCRIPTOR otherwise.
|
||||
*/
|
||||
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
||||
const uint8_t wIndex,
|
||||
const void** const DescriptorAddress
|
||||
#if (defined(ARCH_HAS_MULTI_ADDRESS_SPACE) || defined(__DOXYGEN__)) && \
|
||||
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
|
||||
, uint8_t* MemoryAddressSpace
|
||||
#endif
|
||||
) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/Device_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/Device_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/Device_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Endpoint definitions for all architectures.
|
||||
* \copydetails Group_EndpointManagement
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_EndpointManagement
|
||||
* \defgroup Group_EndpointRW Endpoint Data Reading and Writing
|
||||
* \brief Endpoint data read/write definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_EndpointRW
|
||||
* \defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types
|
||||
* \brief Endpoint data primitive read/write definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing of primitive data types
|
||||
* from and to endpoints.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_EndpointManagement
|
||||
* \defgroup Group_EndpointPacketManagement Endpoint Packet Management
|
||||
* \brief USB Endpoint package management definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to packet management of endpoints.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_EndpointManagement Endpoint Management
|
||||
* \brief Endpoint management definitions.
|
||||
*
|
||||
* Functions, macros and enums related to endpoint management when in USB Device mode. This
|
||||
* module contains the endpoint management macros, as well as endpoint interrupt and data
|
||||
* send/receive functions for various data types.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __ENDPOINT_H__
|
||||
#define __ENDPOINT_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
|
||||
* numerical address in the device.
|
||||
*/
|
||||
#define ENDPOINT_EPNUM_MASK 0x07
|
||||
|
||||
/** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
|
||||
* direction for comparing with the \c ENDPOINT_DESCRIPTOR_DIR_* masks.
|
||||
*/
|
||||
#define ENDPOINT_EPDIR_MASK 0x80
|
||||
|
||||
/** Endpoint address for the default control endpoint, which always resides in address 0. This is
|
||||
* defined for convenience to give more readable code when used with the endpoint macros.
|
||||
*/
|
||||
#define ENDPOINT_CONTROLEP 0
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/Endpoint_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/Endpoint_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/Endpoint_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Endpoint definitions for all architectures.
|
||||
* \copydetails Group_EndpointManagement
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_EndpointManagement
|
||||
* \defgroup Group_EndpointRW Endpoint Data Reading and Writing
|
||||
* \brief Endpoint data read/write definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_EndpointRW
|
||||
* \defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types
|
||||
* \brief Endpoint data primitive read/write definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing of primitive data types
|
||||
* from and to endpoints.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_EndpointManagement
|
||||
* \defgroup Group_EndpointPacketManagement Endpoint Packet Management
|
||||
* \brief USB Endpoint package management definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to packet management of endpoints.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_EndpointManagement Endpoint Management
|
||||
* \brief Endpoint management definitions.
|
||||
*
|
||||
* Functions, macros and enums related to endpoint management when in USB Device mode. This
|
||||
* module contains the endpoint management macros, as well as endpoint interrupt and data
|
||||
* send/receive functions for various data types.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __ENDPOINT_H__
|
||||
#define __ENDPOINT_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
|
||||
* numerical address in the device.
|
||||
*/
|
||||
#define ENDPOINT_EPNUM_MASK 0x07
|
||||
|
||||
/** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
|
||||
* direction for comparing with the \c ENDPOINT_DESCRIPTOR_DIR_* masks.
|
||||
*/
|
||||
#define ENDPOINT_EPDIR_MASK 0x80
|
||||
|
||||
/** Endpoint address for the default control endpoint, which always resides in address 0. This is
|
||||
* defined for convenience to give more readable code when used with the endpoint macros.
|
||||
*/
|
||||
#define ENDPOINT_CONTROLEP 0
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/Endpoint_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/Endpoint_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/Endpoint_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,124 +1,124 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Endpoint data stream transmission and reception management.
|
||||
* \copydetails Group_EndpointStreamRW
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_EndpointRW
|
||||
* \defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams
|
||||
* \brief Endpoint data stream transmission and reception management.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing of data streams from
|
||||
* and to endpoints.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __ENDPOINT_STREAM_H__
|
||||
#define __ENDPOINT_STREAM_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for the possible error return codes of the \c Endpoint_*_Stream_* functions. */
|
||||
enum Endpoint_Stream_RW_ErrorCodes_t
|
||||
{
|
||||
ENDPOINT_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
|
||||
ENDPOINT_RWSTREAM_EndpointStalled = 1, /**< The endpoint was stalled during the stream
|
||||
* transfer by the host or device.
|
||||
*/
|
||||
ENDPOINT_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
|
||||
* the transfer.
|
||||
*/
|
||||
ENDPOINT_RWSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
|
||||
* no USB endpoint traffic can occur until the bus
|
||||
* has resumed.
|
||||
*/
|
||||
ENDPOINT_RWSTREAM_Timeout = 4, /**< The host failed to accept or send the next packet
|
||||
* within the software timeout period set by the
|
||||
* \ref USB_STREAM_TIMEOUT_MS macro.
|
||||
*/
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer = 5, /**< Indicates that the endpoint bank became full or empty before
|
||||
* the complete contents of the current stream could be
|
||||
* transferred. The endpoint stream function should be called
|
||||
* again to process the next chunk of data in the transfer.
|
||||
*/
|
||||
};
|
||||
|
||||
/** Enum for the possible error return codes of the \c Endpoint_*_Control_Stream_* functions. */
|
||||
enum Endpoint_ControlStream_RW_ErrorCodes_t
|
||||
{
|
||||
ENDPOINT_RWCSTREAM_NoError = 0, /**< Command completed successfully, no error. */
|
||||
ENDPOINT_RWCSTREAM_HostAborted = 1, /**< The aborted the transfer prematurely. */
|
||||
ENDPOINT_RWCSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
|
||||
* the transfer.
|
||||
*/
|
||||
ENDPOINT_RWCSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
|
||||
* no USB endpoint traffic can occur until the bus
|
||||
* has resumed.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/EndpointStream_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/EndpointStream_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/EndpointStream_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Endpoint data stream transmission and reception management.
|
||||
* \copydetails Group_EndpointStreamRW
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_EndpointRW
|
||||
* \defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams
|
||||
* \brief Endpoint data stream transmission and reception management.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing of data streams from
|
||||
* and to endpoints.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __ENDPOINT_STREAM_H__
|
||||
#define __ENDPOINT_STREAM_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for the possible error return codes of the \c Endpoint_*_Stream_* functions. */
|
||||
enum Endpoint_Stream_RW_ErrorCodes_t
|
||||
{
|
||||
ENDPOINT_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
|
||||
ENDPOINT_RWSTREAM_EndpointStalled = 1, /**< The endpoint was stalled during the stream
|
||||
* transfer by the host or device.
|
||||
*/
|
||||
ENDPOINT_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
|
||||
* the transfer.
|
||||
*/
|
||||
ENDPOINT_RWSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
|
||||
* no USB endpoint traffic can occur until the bus
|
||||
* has resumed.
|
||||
*/
|
||||
ENDPOINT_RWSTREAM_Timeout = 4, /**< The host failed to accept or send the next packet
|
||||
* within the software timeout period set by the
|
||||
* \ref USB_STREAM_TIMEOUT_MS macro.
|
||||
*/
|
||||
ENDPOINT_RWSTREAM_IncompleteTransfer = 5, /**< Indicates that the endpoint bank became full or empty before
|
||||
* the complete contents of the current stream could be
|
||||
* transferred. The endpoint stream function should be called
|
||||
* again to process the next chunk of data in the transfer.
|
||||
*/
|
||||
};
|
||||
|
||||
/** Enum for the possible error return codes of the \c Endpoint_*_Control_Stream_* functions. */
|
||||
enum Endpoint_ControlStream_RW_ErrorCodes_t
|
||||
{
|
||||
ENDPOINT_RWCSTREAM_NoError = 0, /**< Command completed successfully, no error. */
|
||||
ENDPOINT_RWCSTREAM_HostAborted = 1, /**< The aborted the transfer prematurely. */
|
||||
ENDPOINT_RWCSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
|
||||
* the transfer.
|
||||
*/
|
||||
ENDPOINT_RWCSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
|
||||
* no USB endpoint traffic can occur until the bus
|
||||
* has resumed.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/EndpointStream_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/EndpointStream_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/EndpointStream_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,139 +1,139 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB Host definitions for all architectures.
|
||||
* \copydetails Group_Host
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_Host Host Management
|
||||
* \brief USB Host management definitions for USB host mode.
|
||||
*
|
||||
* USB Host mode related macros and enums. This module contains macros and enums which are used when
|
||||
* the USB controller is initialized in host mode.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBHOST_H__
|
||||
#define __USBHOST_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for the various states of the USB Host state machine.
|
||||
*
|
||||
* For information on each possible USB host state, refer to the USB 2.0 specification.
|
||||
* Several of the USB host states are broken up further into multiple smaller sub-states,
|
||||
* so that they can be internally implemented inside the library in an efficient manner.
|
||||
*
|
||||
* \see \ref USB_HostState, which stores the current host state machine state.
|
||||
*/
|
||||
enum USB_Host_States_t
|
||||
{
|
||||
HOST_STATE_WaitForDevice = 0, /**< This state indicates that the stack is waiting for an interval
|
||||
* to elapse before continuing with the next step of the device
|
||||
* enumeration process.
|
||||
*/
|
||||
HOST_STATE_Unattached = 1, /**< This state indicates that the host state machine is waiting for
|
||||
* a device to be attached so that it can start the enumeration process.
|
||||
*/
|
||||
HOST_STATE_Powered = 2, /**< This state indicates that a device has been attached, and the
|
||||
* library's internals are being configured to begin the enumeration
|
||||
* process.
|
||||
*/
|
||||
HOST_STATE_Powered_WaitForDeviceSettle = 3, /**< This state indicates that the stack is waiting for the initial
|
||||
* settling period to elapse before beginning the enumeration process.
|
||||
*/
|
||||
HOST_STATE_Powered_WaitForConnect = 4, /**< This state indicates that the stack is waiting for a connection event
|
||||
* from the USB controller to indicate a valid USB device has been attached
|
||||
* to the bus and is ready to be enumerated.
|
||||
*/
|
||||
HOST_STATE_Powered_DoReset = 5, /**< This state indicates that a valid USB device has been attached, and that
|
||||
* it will now be reset to ensure it is ready for enumeration.
|
||||
*/
|
||||
HOST_STATE_Powered_ConfigPipe = 6, /**< This state indicates that the attached device is currently powered and
|
||||
* reset, and that the control pipe is now being configured by the stack.
|
||||
*/
|
||||
HOST_STATE_Default = 7, /**< This state indicates that the stack is currently retrieving the control
|
||||
* endpoint's size from the device, so that the control pipe can be altered
|
||||
* to match.
|
||||
*/
|
||||
HOST_STATE_Default_PostReset = 8, /**< This state indicates that the control pipe is being reconfigured to match
|
||||
* the retrieved control endpoint size from the device, and the device's USB
|
||||
* bus address is being set.
|
||||
*/
|
||||
HOST_STATE_Default_PostAddressSet = 9, /**< This state indicates that the device's address has now been set, and the
|
||||
* stack is has now completed the device enumeration process. This state causes
|
||||
* the stack to change the current USB device address to that set for the
|
||||
* connected device, before progressing to the \ref HOST_STATE_Addressed state
|
||||
* ready for use in the user application.
|
||||
*/
|
||||
HOST_STATE_Addressed = 10, /**< Indicates that the device has been enumerated and addressed, and is now waiting
|
||||
* for the user application to configure the device ready for use.
|
||||
*/
|
||||
HOST_STATE_Configured = 11, /**< Indicates that the device has been configured into a valid device configuration,
|
||||
* ready for general use by the user application.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/Host_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/Host_UC3.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB Host definitions for all architectures.
|
||||
* \copydetails Group_Host
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_Host Host Management
|
||||
* \brief USB Host management definitions for USB host mode.
|
||||
*
|
||||
* USB Host mode related macros and enums. This module contains macros and enums which are used when
|
||||
* the USB controller is initialized in host mode.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBHOST_H__
|
||||
#define __USBHOST_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for the various states of the USB Host state machine.
|
||||
*
|
||||
* For information on each possible USB host state, refer to the USB 2.0 specification.
|
||||
* Several of the USB host states are broken up further into multiple smaller sub-states,
|
||||
* so that they can be internally implemented inside the library in an efficient manner.
|
||||
*
|
||||
* \see \ref USB_HostState, which stores the current host state machine state.
|
||||
*/
|
||||
enum USB_Host_States_t
|
||||
{
|
||||
HOST_STATE_WaitForDevice = 0, /**< This state indicates that the stack is waiting for an interval
|
||||
* to elapse before continuing with the next step of the device
|
||||
* enumeration process.
|
||||
*/
|
||||
HOST_STATE_Unattached = 1, /**< This state indicates that the host state machine is waiting for
|
||||
* a device to be attached so that it can start the enumeration process.
|
||||
*/
|
||||
HOST_STATE_Powered = 2, /**< This state indicates that a device has been attached, and the
|
||||
* library's internals are being configured to begin the enumeration
|
||||
* process.
|
||||
*/
|
||||
HOST_STATE_Powered_WaitForDeviceSettle = 3, /**< This state indicates that the stack is waiting for the initial
|
||||
* settling period to elapse before beginning the enumeration process.
|
||||
*/
|
||||
HOST_STATE_Powered_WaitForConnect = 4, /**< This state indicates that the stack is waiting for a connection event
|
||||
* from the USB controller to indicate a valid USB device has been attached
|
||||
* to the bus and is ready to be enumerated.
|
||||
*/
|
||||
HOST_STATE_Powered_DoReset = 5, /**< This state indicates that a valid USB device has been attached, and that
|
||||
* it will now be reset to ensure it is ready for enumeration.
|
||||
*/
|
||||
HOST_STATE_Powered_ConfigPipe = 6, /**< This state indicates that the attached device is currently powered and
|
||||
* reset, and that the control pipe is now being configured by the stack.
|
||||
*/
|
||||
HOST_STATE_Default = 7, /**< This state indicates that the stack is currently retrieving the control
|
||||
* endpoint's size from the device, so that the control pipe can be altered
|
||||
* to match.
|
||||
*/
|
||||
HOST_STATE_Default_PostReset = 8, /**< This state indicates that the control pipe is being reconfigured to match
|
||||
* the retrieved control endpoint size from the device, and the device's USB
|
||||
* bus address is being set.
|
||||
*/
|
||||
HOST_STATE_Default_PostAddressSet = 9, /**< This state indicates that the device's address has now been set, and the
|
||||
* stack is has now completed the device enumeration process. This state causes
|
||||
* the stack to change the current USB device address to that set for the
|
||||
* connected device, before progressing to the \ref HOST_STATE_Addressed state
|
||||
* ready for use in the user application.
|
||||
*/
|
||||
HOST_STATE_Addressed = 10, /**< Indicates that the device has been enumerated and addressed, and is now waiting
|
||||
* for the user application to configure the device ready for use.
|
||||
*/
|
||||
HOST_STATE_Configured = 11, /**< Indicates that the device has been configured into a valid device configuration,
|
||||
* ready for general use by the user application.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/Host_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/Host_UC3.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB OTG definitions for all architectures.
|
||||
* \copydetails Group_OTG
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_OTG USB On The Go (OTG) Management
|
||||
* \brief USB OTG management definitions.
|
||||
*
|
||||
* This module contains macros for embedded USB hosts with dual role On The Go capabilities, for managing role
|
||||
* exchange. OTG is a way for two USB dual role devices to talk to one another directly without fixed device/host
|
||||
* roles.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBOTG_H__
|
||||
#define __USBOTG_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/OTG_AVR8.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB OTG definitions for all architectures.
|
||||
* \copydetails Group_OTG
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_OTG USB On The Go (OTG) Management
|
||||
* \brief USB OTG management definitions.
|
||||
*
|
||||
* This module contains macros for embedded USB hosts with dual role On The Go capabilities, for managing role
|
||||
* exchange. OTG is a way for two USB dual role devices to talk to one another directly without fixed device/host
|
||||
* roles.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBOTG_H__
|
||||
#define __USBOTG_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/OTG_AVR8.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,136 +1,136 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB Pipe definitions for all architectures.
|
||||
* \copydetails Group_PipeManagement
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeManagement
|
||||
* \defgroup Group_PipeRW Pipe Data Reading and Writing
|
||||
* \brief Pipe data read/write definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing from and to pipes.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeRW
|
||||
* \defgroup Group_PipePrimitiveRW Read/Write of Primitive Data Types
|
||||
* \brief Pipe data primitive read/write definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing of primitive data types
|
||||
* from and to pipes.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeManagement
|
||||
* \defgroup Group_PipePacketManagement Pipe Packet Management
|
||||
* \brief Pipe packet management definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to packet management of pipes.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeManagement
|
||||
* \defgroup Group_PipeControlReq Pipe Control Request Management
|
||||
* \brief Pipe control request definitions.
|
||||
*
|
||||
* Module for host mode request processing. This module allows for the transmission of standard, class and
|
||||
* vendor control requests to the default control endpoint of an attached device while in host mode.
|
||||
*
|
||||
* \see Chapter 9 of the USB 2.0 specification.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_PipeManagement Pipe Management
|
||||
* \brief Pipe management definitions.
|
||||
*
|
||||
* This module contains functions, macros and enums related to pipe management when in USB Host mode. This
|
||||
* module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
|
||||
* for various data types.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __PIPE_H__
|
||||
#define __PIPE_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Pipe address for the default control pipe, which always resides in address 0. This is
|
||||
* defined for convenience to give more readable code when used with the pipe macros.
|
||||
*/
|
||||
#define PIPE_CONTROLPIPE 0
|
||||
|
||||
/** Pipe number mask, for masking against pipe addresses to retrieve the pipe's numerical address
|
||||
* in the device.
|
||||
*/
|
||||
#define PIPE_PIPENUM_MASK 0x07
|
||||
|
||||
/** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
|
||||
* numerical address in the attached device.
|
||||
*/
|
||||
#define PIPE_EPNUM_MASK 0x0F
|
||||
|
||||
/** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
|
||||
* direction for comparing with the \c ENDPOINT_DESCRIPTOR_DIR_* masks.
|
||||
*/
|
||||
#define PIPE_EPDIR_MASK 0x80
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/Pipe_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/Pipe_UC3.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB Pipe definitions for all architectures.
|
||||
* \copydetails Group_PipeManagement
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeManagement
|
||||
* \defgroup Group_PipeRW Pipe Data Reading and Writing
|
||||
* \brief Pipe data read/write definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing from and to pipes.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeRW
|
||||
* \defgroup Group_PipePrimitiveRW Read/Write of Primitive Data Types
|
||||
* \brief Pipe data primitive read/write definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing of primitive data types
|
||||
* from and to pipes.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeManagement
|
||||
* \defgroup Group_PipePacketManagement Pipe Packet Management
|
||||
* \brief Pipe packet management definitions.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to packet management of pipes.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeManagement
|
||||
* \defgroup Group_PipeControlReq Pipe Control Request Management
|
||||
* \brief Pipe control request definitions.
|
||||
*
|
||||
* Module for host mode request processing. This module allows for the transmission of standard, class and
|
||||
* vendor control requests to the default control endpoint of an attached device while in host mode.
|
||||
*
|
||||
* \see Chapter 9 of the USB 2.0 specification.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_PipeManagement Pipe Management
|
||||
* \brief Pipe management definitions.
|
||||
*
|
||||
* This module contains functions, macros and enums related to pipe management when in USB Host mode. This
|
||||
* module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
|
||||
* for various data types.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __PIPE_H__
|
||||
#define __PIPE_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Pipe address for the default control pipe, which always resides in address 0. This is
|
||||
* defined for convenience to give more readable code when used with the pipe macros.
|
||||
*/
|
||||
#define PIPE_CONTROLPIPE 0
|
||||
|
||||
/** Pipe number mask, for masking against pipe addresses to retrieve the pipe's numerical address
|
||||
* in the device.
|
||||
*/
|
||||
#define PIPE_PIPENUM_MASK 0x07
|
||||
|
||||
/** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
|
||||
* numerical address in the attached device.
|
||||
*/
|
||||
#define PIPE_EPNUM_MASK 0x0F
|
||||
|
||||
/** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
|
||||
* direction for comparing with the \c ENDPOINT_DESCRIPTOR_DIR_* masks.
|
||||
*/
|
||||
#define PIPE_EPDIR_MASK 0x80
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/Pipe_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/Pipe_UC3.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,100 +1,100 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Pipe data stream transmission and reception management.
|
||||
* \copydetails Group_PipeStreamRW
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeRW
|
||||
* \defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams
|
||||
* \brief Pipe data stream transmission and reception management.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing of data streams from
|
||||
* and to pipes.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __PIPE_STREAM_H__
|
||||
#define __PIPE_STREAM_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for the possible error return codes of the Pipe_*_Stream_* functions. */
|
||||
enum Pipe_Stream_RW_ErrorCodes_t
|
||||
{
|
||||
PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
|
||||
PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */
|
||||
PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
|
||||
* the transfer.
|
||||
*/
|
||||
PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet
|
||||
* within the software timeout period set by the
|
||||
* \ref USB_STREAM_TIMEOUT_MS macro.
|
||||
*/
|
||||
PIPE_RWSTREAM_IncompleteTransfer = 4, /**< Indicates that the pipe bank became full/empty before the
|
||||
* complete contents of the stream could be transferred.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/PipeStream_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/PipeStream_UC3.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Pipe data stream transmission and reception management.
|
||||
* \copydetails Group_PipeStreamRW
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PipeRW
|
||||
* \defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams
|
||||
* \brief Pipe data stream transmission and reception management.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to data reading and writing of data streams from
|
||||
* and to pipes.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __PIPE_STREAM_H__
|
||||
#define __PIPE_STREAM_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for the possible error return codes of the Pipe_*_Stream_* functions. */
|
||||
enum Pipe_Stream_RW_ErrorCodes_t
|
||||
{
|
||||
PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
|
||||
PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */
|
||||
PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
|
||||
* the transfer.
|
||||
*/
|
||||
PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet
|
||||
* within the software timeout period set by the
|
||||
* \ref USB_STREAM_TIMEOUT_MS macro.
|
||||
*/
|
||||
PIPE_RWSTREAM_IncompleteTransfer = 4, /**< Indicates that the pipe bank became full/empty before the
|
||||
* complete contents of the stream could be transferred.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/PipeStream_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/PipeStream_UC3.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
|
||||
#include "../Device.h"
|
||||
|
||||
void USB_Device_SendRemoteWakeup(void)
|
||||
{
|
||||
USB_CLK_Unfreeze();
|
||||
|
||||
AVR32_USBB.UDCON.rmwkup = true;
|
||||
while (AVR32_USBB.UDCON.rmwkup);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
|
||||
#include "../Device.h"
|
||||
|
||||
void USB_Device_SendRemoteWakeup(void)
|
||||
{
|
||||
USB_CLK_Unfreeze();
|
||||
|
||||
AVR32_USBB.UDCON.rmwkup = true;
|
||||
while (AVR32_USBB.UDCON.rmwkup);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,259 +1,259 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Device definitions for the AVR32 UC3 microcontrollers.
|
||||
* \copydetails Group_Device_UC3
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Device
|
||||
* \defgroup Group_Device_UC3 Device Management (UC3)
|
||||
* \brief USB Device definitions for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* Architecture specific USB Device definitions for the Atmel 32-bit UC3 AVR microcontrollers.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBDEVICE_UC3_H__
|
||||
#define __USBDEVICE_UC3_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../USBController.h"
|
||||
#include "../StdDescriptors.h"
|
||||
#include "../USBInterrupt.h"
|
||||
#include "../Endpoint.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name USB Device Mode Option Masks */
|
||||
//@{
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in low speed (1.5Mb/s) mode.
|
||||
*
|
||||
* \note Restrictions apply on the number, size and type of endpoints which can be used
|
||||
* when running in low speed mode - refer to the USB 2.0 specification.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_LOWSPEED (1 << 0)
|
||||
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in full speed (12Mb/s) mode.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_FULLSPEED (0 << 0)
|
||||
|
||||
#if defined(USB_SERIES_UC3A3_AVR32) || defined(USB_SERIES_UC3A4_AVR32) || defined(__DOXYGEN__)
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in high speed (480Mb/s) mode.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_HIGHSPEED (1 << 1)
|
||||
#endif
|
||||
//@}
|
||||
|
||||
#if (!defined(NO_INTERNAL_SERIAL) && \
|
||||
(defined(USB_SERIES_UC3A3_AVR32) || defined(USB_SERIES_UC3A4_AVR32) || \
|
||||
defined(__DOXYGEN__)))
|
||||
/** String descriptor index for the device's unique serial number string descriptor within the device.
|
||||
* This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
|
||||
* number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
|
||||
* a unique serial number internally, and setting the device descriptors serial number string index to this value
|
||||
* will cause it to use the internal serial number.
|
||||
*
|
||||
* On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
|
||||
* number for the device.
|
||||
*/
|
||||
#define USE_INTERNAL_SERIAL 0xDC
|
||||
|
||||
/** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
|
||||
* model.
|
||||
*/
|
||||
#define INTERNAL_SERIAL_LENGTH_BITS 120
|
||||
|
||||
/** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
|
||||
* model.
|
||||
*/
|
||||
#define INTERNAL_SERIAL_START_ADDRESS 0x80800204
|
||||
#else
|
||||
#define USE_INTERNAL_SERIAL NO_DESCRIPTOR
|
||||
|
||||
#define INTERNAL_SERIAL_LENGTH_BITS 0
|
||||
#define INTERNAL_SERIAL_START_ADDRESS 0
|
||||
#endif
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Sends a Remote Wakeup request to the host. This signals to the host that the device should
|
||||
* be taken out of suspended mode, and communications should resume.
|
||||
*
|
||||
* Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
|
||||
* host computer when the host has suspended all USB devices to enter a low power state.
|
||||
*
|
||||
* \note This macro should only be used if the device has indicated to the host that it
|
||||
* supports the Remote Wakeup feature in the device descriptors, and should only be
|
||||
* issued if the host is currently allowing remote wakeup events from the device (i.e.,
|
||||
* the \ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP
|
||||
* compile time option is used, this macro is unavailable.
|
||||
* \n\n
|
||||
*
|
||||
* \note The USB clock must be running for this function to operate. If the stack is initialized with
|
||||
* the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
|
||||
* before attempting to call this function.
|
||||
*
|
||||
* \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
|
||||
*/
|
||||
void USB_Device_SendRemoteWakeup(void);
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
|
||||
* the frame number is incremented by one.
|
||||
*/
|
||||
static inline uint16_t USB_Device_GetFrameNumber(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint16_t USB_Device_GetFrameNumber(void)
|
||||
{
|
||||
return AVR32_USBB.UDFNUM.fnum;
|
||||
}
|
||||
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
/** Enables the device mode Start Of Frame events. When enabled, this causes the
|
||||
* \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
|
||||
* at the start of each USB frame when enumerated in device mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_EnableSOFEvents(void)
|
||||
{
|
||||
USB_INT_Enable(USB_INT_SOFI);
|
||||
}
|
||||
|
||||
/** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
|
||||
* \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_DisableSOFEvents(void)
|
||||
{
|
||||
USB_INT_Disable(USB_INT_SOFI);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Inline Functions: */
|
||||
static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetLowSpeed(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.ls = true;
|
||||
}
|
||||
|
||||
static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetFullSpeed(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.ls = false;
|
||||
#if defined(USB_DEVICE_OPT_HIGHSPEED)
|
||||
AVR32_USBB.UDCON.spdconf = 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(USB_DEVICE_OPT_HIGHSPEED)
|
||||
static inline void USB_Device_SetHighSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetHighSpeed(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.ls = false;
|
||||
AVR32_USBB.UDCON.spdconf = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
|
||||
{
|
||||
AVR32_USBB.UDCON.uadd = Address;
|
||||
AVR32_USBB.UDCON.adden = true;
|
||||
}
|
||||
|
||||
static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_Device_IsAddressSet(void)
|
||||
{
|
||||
return AVR32_USBB.UDCON.adden;
|
||||
}
|
||||
|
||||
#if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
|
||||
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)
|
||||
{
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
uint8_t* SigReadAddress = (uint8_t*)INTERNAL_SERIAL_START_ADDRESS;
|
||||
|
||||
for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)
|
||||
{
|
||||
uint8_t SerialByte = *SigReadAddress;
|
||||
|
||||
if (SerialCharNum & 0x01)
|
||||
{
|
||||
SerialByte >>= 4;
|
||||
SigReadAddress++;
|
||||
}
|
||||
|
||||
SerialByte &= 0x0F;
|
||||
|
||||
UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
|
||||
(('A' - 10) + SerialByte) : ('0' + SerialByte));
|
||||
}
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Device definitions for the AVR32 UC3 microcontrollers.
|
||||
* \copydetails Group_Device_UC3
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Device
|
||||
* \defgroup Group_Device_UC3 Device Management (UC3)
|
||||
* \brief USB Device definitions for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* Architecture specific USB Device definitions for the Atmel 32-bit UC3 AVR microcontrollers.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBDEVICE_UC3_H__
|
||||
#define __USBDEVICE_UC3_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../USBController.h"
|
||||
#include "../StdDescriptors.h"
|
||||
#include "../USBInterrupt.h"
|
||||
#include "../Endpoint.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name USB Device Mode Option Masks */
|
||||
//@{
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in low speed (1.5Mb/s) mode.
|
||||
*
|
||||
* \note Restrictions apply on the number, size and type of endpoints which can be used
|
||||
* when running in low speed mode - refer to the USB 2.0 specification.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_LOWSPEED (1 << 0)
|
||||
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in full speed (12Mb/s) mode.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_FULLSPEED (0 << 0)
|
||||
|
||||
#if defined(USB_SERIES_UC3A3_AVR32) || defined(USB_SERIES_UC3A4_AVR32) || defined(__DOXYGEN__)
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in high speed (480Mb/s) mode.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_HIGHSPEED (1 << 1)
|
||||
#endif
|
||||
//@}
|
||||
|
||||
#if (!defined(NO_INTERNAL_SERIAL) && \
|
||||
(defined(USB_SERIES_UC3A3_AVR32) || defined(USB_SERIES_UC3A4_AVR32) || \
|
||||
defined(__DOXYGEN__)))
|
||||
/** String descriptor index for the device's unique serial number string descriptor within the device.
|
||||
* This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
|
||||
* number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
|
||||
* a unique serial number internally, and setting the device descriptors serial number string index to this value
|
||||
* will cause it to use the internal serial number.
|
||||
*
|
||||
* On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
|
||||
* number for the device.
|
||||
*/
|
||||
#define USE_INTERNAL_SERIAL 0xDC
|
||||
|
||||
/** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
|
||||
* model.
|
||||
*/
|
||||
#define INTERNAL_SERIAL_LENGTH_BITS 120
|
||||
|
||||
/** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
|
||||
* model.
|
||||
*/
|
||||
#define INTERNAL_SERIAL_START_ADDRESS 0x80800204
|
||||
#else
|
||||
#define USE_INTERNAL_SERIAL NO_DESCRIPTOR
|
||||
|
||||
#define INTERNAL_SERIAL_LENGTH_BITS 0
|
||||
#define INTERNAL_SERIAL_START_ADDRESS 0
|
||||
#endif
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Sends a Remote Wakeup request to the host. This signals to the host that the device should
|
||||
* be taken out of suspended mode, and communications should resume.
|
||||
*
|
||||
* Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
|
||||
* host computer when the host has suspended all USB devices to enter a low power state.
|
||||
*
|
||||
* \note This macro should only be used if the device has indicated to the host that it
|
||||
* supports the Remote Wakeup feature in the device descriptors, and should only be
|
||||
* issued if the host is currently allowing remote wakeup events from the device (i.e.,
|
||||
* the \ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP
|
||||
* compile time option is used, this macro is unavailable.
|
||||
* \n\n
|
||||
*
|
||||
* \note The USB clock must be running for this function to operate. If the stack is initialized with
|
||||
* the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
|
||||
* before attempting to call this function.
|
||||
*
|
||||
* \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
|
||||
*/
|
||||
void USB_Device_SendRemoteWakeup(void);
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
|
||||
* the frame number is incremented by one.
|
||||
*/
|
||||
static inline uint16_t USB_Device_GetFrameNumber(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint16_t USB_Device_GetFrameNumber(void)
|
||||
{
|
||||
return AVR32_USBB.UDFNUM.fnum;
|
||||
}
|
||||
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
/** Enables the device mode Start Of Frame events. When enabled, this causes the
|
||||
* \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
|
||||
* at the start of each USB frame when enumerated in device mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_EnableSOFEvents(void)
|
||||
{
|
||||
USB_INT_Enable(USB_INT_SOFI);
|
||||
}
|
||||
|
||||
/** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
|
||||
* \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_DisableSOFEvents(void)
|
||||
{
|
||||
USB_INT_Disable(USB_INT_SOFI);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Inline Functions: */
|
||||
static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetLowSpeed(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.ls = true;
|
||||
}
|
||||
|
||||
static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetFullSpeed(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.ls = false;
|
||||
#if defined(USB_DEVICE_OPT_HIGHSPEED)
|
||||
AVR32_USBB.UDCON.spdconf = 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(USB_DEVICE_OPT_HIGHSPEED)
|
||||
static inline void USB_Device_SetHighSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetHighSpeed(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.ls = false;
|
||||
AVR32_USBB.UDCON.spdconf = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
|
||||
{
|
||||
AVR32_USBB.UDCON.uadd = Address;
|
||||
AVR32_USBB.UDCON.adden = true;
|
||||
}
|
||||
|
||||
static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_Device_IsAddressSet(void)
|
||||
{
|
||||
return AVR32_USBB.UDCON.adden;
|
||||
}
|
||||
|
||||
#if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
|
||||
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)
|
||||
{
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
uint8_t* SigReadAddress = (uint8_t*)INTERNAL_SERIAL_START_ADDRESS;
|
||||
|
||||
for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)
|
||||
{
|
||||
uint8_t SerialByte = *SigReadAddress;
|
||||
|
||||
if (SerialCharNum & 0x01)
|
||||
{
|
||||
SerialByte >>= 4;
|
||||
SigReadAddress++;
|
||||
}
|
||||
|
||||
SerialByte &= 0x0F;
|
||||
|
||||
UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
|
||||
(('A' - 10) + SerialByte) : ('0' + SerialByte));
|
||||
}
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,141 +1,141 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
|
||||
#include "../Endpoint.h"
|
||||
|
||||
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
|
||||
uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
|
||||
#endif
|
||||
|
||||
volatile uint32_t USB_SelectedEndpoint = ENDPOINT_CONTROLEP;
|
||||
volatile uint8_t* USB_EndpointFIFOPos[ENDPOINT_TOTAL_ENDPOINTS];
|
||||
|
||||
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
|
||||
const uint32_t UECFG0Data)
|
||||
{
|
||||
Endpoint_SelectEndpoint(Number);
|
||||
Endpoint_EnableEndpoint();
|
||||
|
||||
(&AVR32_USBB.uecfg0)[Number] = 0;
|
||||
(&AVR32_USBB.uecfg0)[Number] = UECFG0Data;
|
||||
USB_EndpointFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000];
|
||||
|
||||
return Endpoint_IsConfigured();
|
||||
}
|
||||
|
||||
void Endpoint_ClearEndpoints(void)
|
||||
{
|
||||
for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
|
||||
{
|
||||
Endpoint_SelectEndpoint(EPNum);
|
||||
(&AVR32_USBB.uecfg0)[EPNum] = 0;
|
||||
(&AVR32_USBB.uecon0clr)[EPNum] = -1;
|
||||
USB_EndpointFIFOPos[EPNum] = &AVR32_USBB_SLAVE[EPNum * 0x10000];
|
||||
Endpoint_DisableEndpoint();
|
||||
}
|
||||
}
|
||||
|
||||
void Endpoint_ClearStatusStage(void)
|
||||
{
|
||||
if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)
|
||||
{
|
||||
while (!(Endpoint_IsOUTReceived()))
|
||||
{
|
||||
if (USB_DeviceState == DEVICE_STATE_Unattached)
|
||||
return;
|
||||
}
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
else
|
||||
{
|
||||
while (!(Endpoint_IsINReady()))
|
||||
{
|
||||
if (USB_DeviceState == DEVICE_STATE_Unattached)
|
||||
return;
|
||||
}
|
||||
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(CONTROL_ONLY_DEVICE)
|
||||
uint8_t Endpoint_WaitUntilReady(void)
|
||||
{
|
||||
#if (USB_STREAM_TIMEOUT_MS < 0xFF)
|
||||
uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
|
||||
#else
|
||||
uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
|
||||
#endif
|
||||
|
||||
uint16_t PreviousFrameNumber = USB_Device_GetFrameNumber();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)
|
||||
{
|
||||
if (Endpoint_IsINReady())
|
||||
return ENDPOINT_READYWAIT_NoError;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Endpoint_IsOUTReceived())
|
||||
return ENDPOINT_READYWAIT_NoError;
|
||||
}
|
||||
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_READYWAIT_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_READYWAIT_BusSuspended;
|
||||
else if (Endpoint_IsStalled())
|
||||
return ENDPOINT_READYWAIT_EndpointStalled;
|
||||
|
||||
uint16_t CurrentFrameNumber = USB_Device_GetFrameNumber();
|
||||
|
||||
if (CurrentFrameNumber != PreviousFrameNumber)
|
||||
{
|
||||
PreviousFrameNumber = CurrentFrameNumber;
|
||||
|
||||
if (!(TimeoutMSRem--))
|
||||
return ENDPOINT_READYWAIT_Timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
|
||||
#include "../Endpoint.h"
|
||||
|
||||
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
|
||||
uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
|
||||
#endif
|
||||
|
||||
volatile uint32_t USB_SelectedEndpoint = ENDPOINT_CONTROLEP;
|
||||
volatile uint8_t* USB_EndpointFIFOPos[ENDPOINT_TOTAL_ENDPOINTS];
|
||||
|
||||
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
|
||||
const uint32_t UECFG0Data)
|
||||
{
|
||||
Endpoint_SelectEndpoint(Number);
|
||||
Endpoint_EnableEndpoint();
|
||||
|
||||
(&AVR32_USBB.uecfg0)[Number] = 0;
|
||||
(&AVR32_USBB.uecfg0)[Number] = UECFG0Data;
|
||||
USB_EndpointFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000];
|
||||
|
||||
return Endpoint_IsConfigured();
|
||||
}
|
||||
|
||||
void Endpoint_ClearEndpoints(void)
|
||||
{
|
||||
for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
|
||||
{
|
||||
Endpoint_SelectEndpoint(EPNum);
|
||||
(&AVR32_USBB.uecfg0)[EPNum] = 0;
|
||||
(&AVR32_USBB.uecon0clr)[EPNum] = -1;
|
||||
USB_EndpointFIFOPos[EPNum] = &AVR32_USBB_SLAVE[EPNum * 0x10000];
|
||||
Endpoint_DisableEndpoint();
|
||||
}
|
||||
}
|
||||
|
||||
void Endpoint_ClearStatusStage(void)
|
||||
{
|
||||
if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)
|
||||
{
|
||||
while (!(Endpoint_IsOUTReceived()))
|
||||
{
|
||||
if (USB_DeviceState == DEVICE_STATE_Unattached)
|
||||
return;
|
||||
}
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
else
|
||||
{
|
||||
while (!(Endpoint_IsINReady()))
|
||||
{
|
||||
if (USB_DeviceState == DEVICE_STATE_Unattached)
|
||||
return;
|
||||
}
|
||||
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(CONTROL_ONLY_DEVICE)
|
||||
uint8_t Endpoint_WaitUntilReady(void)
|
||||
{
|
||||
#if (USB_STREAM_TIMEOUT_MS < 0xFF)
|
||||
uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
|
||||
#else
|
||||
uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
|
||||
#endif
|
||||
|
||||
uint16_t PreviousFrameNumber = USB_Device_GetFrameNumber();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)
|
||||
{
|
||||
if (Endpoint_IsINReady())
|
||||
return ENDPOINT_READYWAIT_NoError;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Endpoint_IsOUTReceived())
|
||||
return ENDPOINT_READYWAIT_NoError;
|
||||
}
|
||||
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_READYWAIT_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_READYWAIT_BusSuspended;
|
||||
else if (Endpoint_IsStalled())
|
||||
return ENDPOINT_READYWAIT_EndpointStalled;
|
||||
|
||||
uint16_t CurrentFrameNumber = USB_Device_GetFrameNumber();
|
||||
|
||||
if (CurrentFrameNumber != PreviousFrameNumber)
|
||||
{
|
||||
PreviousFrameNumber = CurrentFrameNumber;
|
||||
|
||||
if (!(TimeoutMSRem--))
|
||||
return ENDPOINT_READYWAIT_Timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,292 +1,292 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#define __INCLUDE_FROM_HOST_C
|
||||
#include "../Host.h"
|
||||
|
||||
void USB_Host_ProcessNextHostState(void)
|
||||
{
|
||||
uint8_t ErrorCode = HOST_ENUMERROR_NoError;
|
||||
uint8_t SubErrorCode = HOST_ENUMERROR_NoError;
|
||||
|
||||
static uint16_t WaitMSRemaining;
|
||||
static uint8_t PostWaitState;
|
||||
|
||||
switch (USB_HostState)
|
||||
{
|
||||
case HOST_STATE_WaitForDevice:
|
||||
if (WaitMSRemaining)
|
||||
{
|
||||
if ((SubErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)
|
||||
{
|
||||
USB_HostState = PostWaitState;
|
||||
ErrorCode = HOST_ENUMERROR_WaitStage;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(--WaitMSRemaining))
|
||||
USB_HostState = PostWaitState;
|
||||
}
|
||||
|
||||
break;
|
||||
case HOST_STATE_Powered:
|
||||
WaitMSRemaining = HOST_DEVICE_SETTLE_DELAY_MS;
|
||||
|
||||
USB_HostState = HOST_STATE_Powered_WaitForDeviceSettle;
|
||||
break;
|
||||
case HOST_STATE_Powered_WaitForDeviceSettle:
|
||||
if (WaitMSRemaining--)
|
||||
{
|
||||
Delay_MS(1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_Host_VBUS_Manual_Off();
|
||||
|
||||
USB_OTGPAD_On();
|
||||
USB_Host_VBUS_Auto_Enable();
|
||||
USB_Host_VBUS_Auto_On();
|
||||
|
||||
USB_HostState = HOST_STATE_Powered_WaitForConnect;
|
||||
}
|
||||
|
||||
break;
|
||||
case HOST_STATE_Powered_WaitForConnect:
|
||||
if (USB_INT_HasOccurred(USB_INT_DCONNI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_DCONNI);
|
||||
USB_INT_Clear(USB_INT_DDISCI);
|
||||
|
||||
USB_INT_Clear(USB_INT_VBERRI);
|
||||
USB_INT_Enable(USB_INT_VBERRI);
|
||||
|
||||
USB_Host_ResumeBus();
|
||||
Pipe_ClearPipes();
|
||||
|
||||
HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Powered_DoReset);
|
||||
}
|
||||
|
||||
break;
|
||||
case HOST_STATE_Powered_DoReset:
|
||||
USB_Host_ResetDevice();
|
||||
|
||||
HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Powered_ConfigPipe);
|
||||
break;
|
||||
case HOST_STATE_Powered_ConfigPipe:
|
||||
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
|
||||
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
|
||||
PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE);
|
||||
|
||||
if (!(Pipe_IsConfigured()))
|
||||
{
|
||||
ErrorCode = HOST_ENUMERROR_PipeConfigError;
|
||||
SubErrorCode = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
USB_HostState = HOST_STATE_Default;
|
||||
break;
|
||||
case HOST_STATE_Default:
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
|
||||
.bRequest = REQ_GetDescriptor,
|
||||
.wValue = (DTYPE_Device << 8),
|
||||
.wIndex = 0,
|
||||
.wLength = 8,
|
||||
};
|
||||
|
||||
uint8_t DataBuffer[8];
|
||||
|
||||
if ((SubErrorCode = USB_Host_SendControlRequest(DataBuffer)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
ErrorCode = HOST_ENUMERROR_ControlError;
|
||||
break;
|
||||
}
|
||||
|
||||
USB_Host_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)];
|
||||
|
||||
USB_Host_ResetDevice();
|
||||
|
||||
HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Default_PostReset);
|
||||
break;
|
||||
case HOST_STATE_Default_PostReset:
|
||||
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
|
||||
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
|
||||
USB_Host_ControlPipeSize, PIPE_BANK_SINGLE);
|
||||
|
||||
if (!(Pipe_IsConfigured()))
|
||||
{
|
||||
ErrorCode = HOST_ENUMERROR_PipeConfigError;
|
||||
SubErrorCode = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
|
||||
.bRequest = REQ_SetAddress,
|
||||
.wValue = USB_HOST_DEVICEADDRESS,
|
||||
.wIndex = 0,
|
||||
.wLength = 0,
|
||||
};
|
||||
|
||||
if ((SubErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
ErrorCode = HOST_ENUMERROR_ControlError;
|
||||
break;
|
||||
}
|
||||
|
||||
HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Default_PostAddressSet);
|
||||
break;
|
||||
case HOST_STATE_Default_PostAddressSet:
|
||||
USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS);
|
||||
|
||||
USB_HostState = HOST_STATE_Addressed;
|
||||
|
||||
EVENT_USB_Host_DeviceEnumerationComplete();
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ErrorCode != HOST_ENUMERROR_NoError) && (USB_HostState != HOST_STATE_Unattached))
|
||||
{
|
||||
EVENT_USB_Host_DeviceEnumerationFailed(ErrorCode, SubErrorCode);
|
||||
|
||||
USB_Host_VBUS_Auto_Off();
|
||||
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t USB_Host_WaitMS(uint8_t MS)
|
||||
{
|
||||
bool BusSuspended = USB_Host_IsBusSuspended();
|
||||
uint8_t ErrorCode = HOST_WAITERROR_Successful;
|
||||
bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
|
||||
|
||||
USB_INT_Disable(USB_INT_HSOFI);
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
|
||||
USB_Host_ResumeBus();
|
||||
|
||||
while (MS)
|
||||
{
|
||||
if (USB_INT_HasOccurred(USB_INT_HSOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
MS--;
|
||||
}
|
||||
|
||||
if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode != USB_MODE_Host))
|
||||
{
|
||||
ErrorCode = HOST_WAITERROR_DeviceDisconnect;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Pipe_IsError() == true)
|
||||
{
|
||||
Pipe_ClearError();
|
||||
ErrorCode = HOST_WAITERROR_PipeError;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Pipe_IsStalled() == true)
|
||||
{
|
||||
Pipe_ClearStall();
|
||||
ErrorCode = HOST_WAITERROR_SetupStalled;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (BusSuspended)
|
||||
USB_Host_SuspendBus();
|
||||
|
||||
if (HSOFIEnabled)
|
||||
USB_INT_Enable(USB_INT_HSOFI);
|
||||
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
static void USB_Host_ResetDevice(void)
|
||||
{
|
||||
bool BusSuspended = USB_Host_IsBusSuspended();
|
||||
|
||||
USB_INT_Disable(USB_INT_DDISCI);
|
||||
|
||||
USB_Host_ResetBus();
|
||||
while (!(USB_Host_IsBusResetComplete()));
|
||||
USB_Host_ResumeBus();
|
||||
|
||||
USB_Host_ConfigurationNumber = 0;
|
||||
|
||||
bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
|
||||
|
||||
USB_INT_Disable(USB_INT_HSOFI);
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
|
||||
for (uint8_t MSRem = 10; MSRem != 0; MSRem--)
|
||||
{
|
||||
/* Workaround for powerless-pull-up devices. After a USB bus reset,
|
||||
all disconnection interrupts are suppressed while a USB frame is
|
||||
looked for - if it is found within 10ms, the device is still
|
||||
present. */
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_HSOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
USB_INT_Clear(USB_INT_DDISCI);
|
||||
break;
|
||||
}
|
||||
|
||||
Delay_MS(1);
|
||||
}
|
||||
|
||||
if (HSOFIEnabled)
|
||||
USB_INT_Enable(USB_INT_HSOFI);
|
||||
|
||||
if (BusSuspended)
|
||||
USB_Host_SuspendBus();
|
||||
|
||||
USB_INT_Enable(USB_INT_DDISCI);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#define __INCLUDE_FROM_HOST_C
|
||||
#include "../Host.h"
|
||||
|
||||
void USB_Host_ProcessNextHostState(void)
|
||||
{
|
||||
uint8_t ErrorCode = HOST_ENUMERROR_NoError;
|
||||
uint8_t SubErrorCode = HOST_ENUMERROR_NoError;
|
||||
|
||||
static uint16_t WaitMSRemaining;
|
||||
static uint8_t PostWaitState;
|
||||
|
||||
switch (USB_HostState)
|
||||
{
|
||||
case HOST_STATE_WaitForDevice:
|
||||
if (WaitMSRemaining)
|
||||
{
|
||||
if ((SubErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)
|
||||
{
|
||||
USB_HostState = PostWaitState;
|
||||
ErrorCode = HOST_ENUMERROR_WaitStage;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(--WaitMSRemaining))
|
||||
USB_HostState = PostWaitState;
|
||||
}
|
||||
|
||||
break;
|
||||
case HOST_STATE_Powered:
|
||||
WaitMSRemaining = HOST_DEVICE_SETTLE_DELAY_MS;
|
||||
|
||||
USB_HostState = HOST_STATE_Powered_WaitForDeviceSettle;
|
||||
break;
|
||||
case HOST_STATE_Powered_WaitForDeviceSettle:
|
||||
if (WaitMSRemaining--)
|
||||
{
|
||||
Delay_MS(1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_Host_VBUS_Manual_Off();
|
||||
|
||||
USB_OTGPAD_On();
|
||||
USB_Host_VBUS_Auto_Enable();
|
||||
USB_Host_VBUS_Auto_On();
|
||||
|
||||
USB_HostState = HOST_STATE_Powered_WaitForConnect;
|
||||
}
|
||||
|
||||
break;
|
||||
case HOST_STATE_Powered_WaitForConnect:
|
||||
if (USB_INT_HasOccurred(USB_INT_DCONNI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_DCONNI);
|
||||
USB_INT_Clear(USB_INT_DDISCI);
|
||||
|
||||
USB_INT_Clear(USB_INT_VBERRI);
|
||||
USB_INT_Enable(USB_INT_VBERRI);
|
||||
|
||||
USB_Host_ResumeBus();
|
||||
Pipe_ClearPipes();
|
||||
|
||||
HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Powered_DoReset);
|
||||
}
|
||||
|
||||
break;
|
||||
case HOST_STATE_Powered_DoReset:
|
||||
USB_Host_ResetDevice();
|
||||
|
||||
HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Powered_ConfigPipe);
|
||||
break;
|
||||
case HOST_STATE_Powered_ConfigPipe:
|
||||
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
|
||||
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
|
||||
PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE);
|
||||
|
||||
if (!(Pipe_IsConfigured()))
|
||||
{
|
||||
ErrorCode = HOST_ENUMERROR_PipeConfigError;
|
||||
SubErrorCode = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
USB_HostState = HOST_STATE_Default;
|
||||
break;
|
||||
case HOST_STATE_Default:
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
|
||||
.bRequest = REQ_GetDescriptor,
|
||||
.wValue = (DTYPE_Device << 8),
|
||||
.wIndex = 0,
|
||||
.wLength = 8,
|
||||
};
|
||||
|
||||
uint8_t DataBuffer[8];
|
||||
|
||||
if ((SubErrorCode = USB_Host_SendControlRequest(DataBuffer)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
ErrorCode = HOST_ENUMERROR_ControlError;
|
||||
break;
|
||||
}
|
||||
|
||||
USB_Host_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)];
|
||||
|
||||
USB_Host_ResetDevice();
|
||||
|
||||
HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Default_PostReset);
|
||||
break;
|
||||
case HOST_STATE_Default_PostReset:
|
||||
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
|
||||
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
|
||||
USB_Host_ControlPipeSize, PIPE_BANK_SINGLE);
|
||||
|
||||
if (!(Pipe_IsConfigured()))
|
||||
{
|
||||
ErrorCode = HOST_ENUMERROR_PipeConfigError;
|
||||
SubErrorCode = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
|
||||
.bRequest = REQ_SetAddress,
|
||||
.wValue = USB_HOST_DEVICEADDRESS,
|
||||
.wIndex = 0,
|
||||
.wLength = 0,
|
||||
};
|
||||
|
||||
if ((SubErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
ErrorCode = HOST_ENUMERROR_ControlError;
|
||||
break;
|
||||
}
|
||||
|
||||
HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Default_PostAddressSet);
|
||||
break;
|
||||
case HOST_STATE_Default_PostAddressSet:
|
||||
USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS);
|
||||
|
||||
USB_HostState = HOST_STATE_Addressed;
|
||||
|
||||
EVENT_USB_Host_DeviceEnumerationComplete();
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ErrorCode != HOST_ENUMERROR_NoError) && (USB_HostState != HOST_STATE_Unattached))
|
||||
{
|
||||
EVENT_USB_Host_DeviceEnumerationFailed(ErrorCode, SubErrorCode);
|
||||
|
||||
USB_Host_VBUS_Auto_Off();
|
||||
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t USB_Host_WaitMS(uint8_t MS)
|
||||
{
|
||||
bool BusSuspended = USB_Host_IsBusSuspended();
|
||||
uint8_t ErrorCode = HOST_WAITERROR_Successful;
|
||||
bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
|
||||
|
||||
USB_INT_Disable(USB_INT_HSOFI);
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
|
||||
USB_Host_ResumeBus();
|
||||
|
||||
while (MS)
|
||||
{
|
||||
if (USB_INT_HasOccurred(USB_INT_HSOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
MS--;
|
||||
}
|
||||
|
||||
if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode != USB_MODE_Host))
|
||||
{
|
||||
ErrorCode = HOST_WAITERROR_DeviceDisconnect;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Pipe_IsError() == true)
|
||||
{
|
||||
Pipe_ClearError();
|
||||
ErrorCode = HOST_WAITERROR_PipeError;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Pipe_IsStalled() == true)
|
||||
{
|
||||
Pipe_ClearStall();
|
||||
ErrorCode = HOST_WAITERROR_SetupStalled;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (BusSuspended)
|
||||
USB_Host_SuspendBus();
|
||||
|
||||
if (HSOFIEnabled)
|
||||
USB_INT_Enable(USB_INT_HSOFI);
|
||||
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
static void USB_Host_ResetDevice(void)
|
||||
{
|
||||
bool BusSuspended = USB_Host_IsBusSuspended();
|
||||
|
||||
USB_INT_Disable(USB_INT_DDISCI);
|
||||
|
||||
USB_Host_ResetBus();
|
||||
while (!(USB_Host_IsBusResetComplete()));
|
||||
USB_Host_ResumeBus();
|
||||
|
||||
USB_Host_ConfigurationNumber = 0;
|
||||
|
||||
bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
|
||||
|
||||
USB_INT_Disable(USB_INT_HSOFI);
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
|
||||
for (uint8_t MSRem = 10; MSRem != 0; MSRem--)
|
||||
{
|
||||
/* Workaround for powerless-pull-up devices. After a USB bus reset,
|
||||
all disconnection interrupts are suppressed while a USB frame is
|
||||
looked for - if it is found within 10ms, the device is still
|
||||
present. */
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_HSOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
USB_INT_Clear(USB_INT_DDISCI);
|
||||
break;
|
||||
}
|
||||
|
||||
Delay_MS(1);
|
||||
}
|
||||
|
||||
if (HSOFIEnabled)
|
||||
USB_INT_Enable(USB_INT_HSOFI);
|
||||
|
||||
if (BusSuspended)
|
||||
USB_Host_SuspendBus();
|
||||
|
||||
USB_INT_Enable(USB_INT_DDISCI);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,372 +1,372 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Host definitions for the AVR32 UC3B microcontrollers.
|
||||
* \copydetails Group_Host_UC3B
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Host
|
||||
* \defgroup Group_Host_UC3B Host Management (UC3B)
|
||||
* \brief USB Host definitions for the AVR32 UC3B microcontrollers.
|
||||
*
|
||||
* Architecture specific USB Host definitions for the Atmel 32-bit AVR UC3B microcontrollers.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBHOST_UC3B_H__
|
||||
#define __USBHOST_UC3B_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../StdDescriptors.h"
|
||||
#include "../Pipe.h"
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Indicates the fixed USB device address which any attached device is enumerated to when in
|
||||
* host mode. As only one USB device may be attached to the AVR in host mode at any one time
|
||||
* and that the address used is not important (other than the fact that it is non-zero), a
|
||||
* fixed value is specified by the library.
|
||||
*/
|
||||
#define USB_HOST_DEVICEADDRESS 1
|
||||
|
||||
#if !defined(USB_HOST_TIMEOUT_MS) || defined(__DOXYGEN__)
|
||||
/** Constant for the maximum software timeout period of sent USB control transactions to an attached
|
||||
* device. If a device fails to respond to a sent control request within this period, the
|
||||
* library will return a timeout error code.
|
||||
*
|
||||
* This value may be overridden in the user project makefile as the value of the
|
||||
* \ref USB_HOST_TIMEOUT_MS token, and passed to the compiler using the -D switch.
|
||||
*/
|
||||
#define USB_HOST_TIMEOUT_MS 1000
|
||||
#endif
|
||||
|
||||
#if !defined(HOST_DEVICE_SETTLE_DELAY_MS) || defined(__DOXYGEN__)
|
||||
/** Constant for the delay in milliseconds after a device is connected before the library
|
||||
* will start the enumeration process. Some devices require a delay of up to 5 seconds
|
||||
* after connection before the enumeration process can start or incorrect operation will
|
||||
* occur.
|
||||
*
|
||||
* The default delay value may be overridden in the user project makefile by defining the
|
||||
* \c HOST_DEVICE_SETTLE_DELAY_MS token to the required delay in milliseconds, and passed to the
|
||||
* compiler using the -D switch.
|
||||
*/
|
||||
#define HOST_DEVICE_SETTLE_DELAY_MS 1000
|
||||
#endif
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the error codes for the \ref EVENT_USB_Host_HostError() event.
|
||||
*
|
||||
* \see \ref Group_Events for more information on this event.
|
||||
*/
|
||||
enum USB_Host_ErrorCodes_t
|
||||
{
|
||||
HOST_ERROR_VBusVoltageDip = 0, /**< VBUS voltage dipped to an unacceptable level. This
|
||||
* error may be the result of an attached device drawing
|
||||
* too much current from the VBUS line, or due to the
|
||||
* AVR's power source being unable to supply sufficient
|
||||
* current.
|
||||
*/
|
||||
};
|
||||
|
||||
/** Enum for the error codes for the \ref EVENT_USB_Host_DeviceEnumerationFailed() event.
|
||||
*
|
||||
* \see \ref Group_Events for more information on this event.
|
||||
*/
|
||||
enum USB_Host_EnumerationErrorCodes_t
|
||||
{
|
||||
HOST_ENUMERROR_NoError = 0, /**< No error occurred. Used internally, this is not a valid
|
||||
* ErrorCode parameter value for the \ref EVENT_USB_Host_DeviceEnumerationFailed()
|
||||
* event.
|
||||
*/
|
||||
HOST_ENUMERROR_WaitStage = 1, /**< One of the delays between enumeration steps failed
|
||||
* to complete successfully, due to a timeout or other
|
||||
* error.
|
||||
*/
|
||||
HOST_ENUMERROR_NoDeviceDetected = 2, /**< No device was detected, despite the USB data lines
|
||||
* indicating the attachment of a device.
|
||||
*/
|
||||
HOST_ENUMERROR_ControlError = 3, /**< One of the enumeration control requests failed to
|
||||
* complete successfully.
|
||||
*/
|
||||
HOST_ENUMERROR_PipeConfigError = 4, /**< The default control pipe (address 0) failed to
|
||||
* configure correctly.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Returns the current USB frame number, when in host mode. Every millisecond the USB bus is active (i.e. not suspended)
|
||||
* the frame number is incremented by one.
|
||||
*/
|
||||
static inline uint16_t USB_Host_GetFrameNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline uint16_t USB_Host_GetFrameNumber(void)
|
||||
{
|
||||
return AVR32_USBB_UHFNUM;
|
||||
}
|
||||
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
/** Enables the host mode Start Of Frame events. When enabled, this causes the
|
||||
* \ref EVENT_USB_Host_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
|
||||
* at the start of each USB frame when a device is enumerated while in host mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Host_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_EnableSOFEvents(void)
|
||||
{
|
||||
USB_INT_Enable(USB_INT_HSOFI);
|
||||
}
|
||||
|
||||
/** Disables the host mode Start Of Frame events. When disabled, this stops the firing of the
|
||||
* \ref EVENT_USB_Host_StartOfFrame() event when enumerated in host mode.
|
||||
*
|
||||
* \note Not available when the NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Host_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_DisableSOFEvents(void)
|
||||
{
|
||||
USB_INT_Disable(USB_INT_HSOFI);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Resets the USB bus, including the endpoints in any attached device and pipes on the AVR host.
|
||||
* USB bus resets leave the default control pipe configured (if already configured).
|
||||
*
|
||||
* If the USB bus has been suspended prior to issuing a bus reset, the attached device will be
|
||||
* woken up automatically and the bus resumed after the reset has been correctly issued.
|
||||
*/
|
||||
static inline void USB_Host_ResetBus(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_ResetBus(void)
|
||||
{
|
||||
AVR32_USBB.UHCON.reset = true;
|
||||
}
|
||||
|
||||
/** Determines if a previously issued bus reset (via the \ref USB_Host_ResetBus() macro) has
|
||||
* completed.
|
||||
*
|
||||
* \return Boolean \c true if no bus reset is currently being sent, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsBusResetComplete(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsBusResetComplete(void)
|
||||
{
|
||||
return AVR32_USBB.UHCON.reset;
|
||||
}
|
||||
|
||||
/** Resumes USB communications with an attached and enumerated device, by resuming the transmission
|
||||
* of the 1MS Start Of Frame messages to the device. When resumed, USB communications between the
|
||||
* host and attached device may occur.
|
||||
*/
|
||||
static inline void USB_Host_ResumeBus(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_ResumeBus(void)
|
||||
{
|
||||
AVR32_USBB.UHCON.sofe = true;
|
||||
}
|
||||
|
||||
/** Suspends the USB bus, preventing any communications from occurring between the host and attached
|
||||
* device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame
|
||||
* messages to the device.
|
||||
*
|
||||
* \note While the USB bus is suspended, all USB interrupt sources are also disabled; this means that
|
||||
* some events (such as device disconnections) will not fire until the bus is resumed.
|
||||
*/
|
||||
static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_SuspendBus(void)
|
||||
{
|
||||
AVR32_USBB.UHCON.sofe = false;
|
||||
}
|
||||
|
||||
/** Determines if the USB bus has been suspended via the use of the \ref USB_Host_SuspendBus() macro,
|
||||
* false otherwise. While suspended, no USB communications can occur until the bus is resumed,
|
||||
* except for the Remote Wakeup event from the device if supported.
|
||||
*
|
||||
* \return Boolean \c true if the bus is currently suspended, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsBusSuspended(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsBusSuspended(void)
|
||||
{
|
||||
return AVR32_USBB.UHCON.sofe;
|
||||
}
|
||||
|
||||
/** Determines if the attached device is currently enumerated in Full Speed mode (12Mb/s), or
|
||||
* false if the attached device is enumerated in Low Speed mode (1.5Mb/s).
|
||||
*
|
||||
* \return Boolean \c true if the attached device is enumerated in Full Speed mode, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsDeviceFullSpeed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsDeviceFullSpeed(void)
|
||||
{
|
||||
return (AVR32_USBB.USBSTA.speed == AVR32_USBB_SPEED_FULL);
|
||||
}
|
||||
|
||||
/** Determines if the attached device is currently issuing a Remote Wakeup request, requesting
|
||||
* that the host resume the USB bus and wake up the device, false otherwise.
|
||||
*
|
||||
* \return Boolean \c true if the attached device has sent a Remote Wakeup request, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsRemoteWakeupSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsRemoteWakeupSent(void)
|
||||
{
|
||||
return AVR32_USBB.UHINT.rxrsmi;
|
||||
}
|
||||
|
||||
/** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */
|
||||
static inline void USB_Host_ClearRemoteWakeupSent(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_ClearRemoteWakeupSent(void)
|
||||
{
|
||||
AVR32_USBB.UHINTCLR.rxrsmic = true;
|
||||
}
|
||||
|
||||
/** Accepts a Remote Wakeup request from an attached device. This must be issued in response to
|
||||
* a device's Remote Wakeup request within 2ms for the request to be accepted and the bus to
|
||||
* be resumed.
|
||||
*/
|
||||
static inline void USB_Host_ResumeFromWakeupRequest(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_ResumeFromWakeupRequest(void)
|
||||
{
|
||||
AVR32_USBB.UHCON.resume = true;
|
||||
}
|
||||
|
||||
/** Determines if a resume from Remote Wakeup request is currently being sent to an attached
|
||||
* device.
|
||||
*
|
||||
* \return Boolean \c true if no resume request is currently being sent, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsResumeFromWakeupRequestSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsResumeFromWakeupRequestSent(void)
|
||||
{
|
||||
return AVR32_USBB.UHCON.resume;
|
||||
}
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
static inline void USB_Host_HostMode_On(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_HostMode_On(void)
|
||||
{
|
||||
// Not required for UC3B
|
||||
}
|
||||
|
||||
static inline void USB_Host_HostMode_Off(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_HostMode_Off(void)
|
||||
{
|
||||
// Not required for UC3B
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Auto_Enable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Auto_Enable(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.vbushwc = false;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Manual_Enable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Manual_Enable(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.vbushwc = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Auto_On(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Auto_On(void)
|
||||
{
|
||||
AVR32_USBB.USBSTASET.vbusrqs = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Manual_On(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Manual_On(void)
|
||||
{
|
||||
AVR32_USBB.USBSTASET.vbusrqs = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Auto_Off(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Auto_Off(void)
|
||||
{
|
||||
AVR32_USBB.USBSTACLR.vbusrqc = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Manual_Off(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Manual_Off(void)
|
||||
{
|
||||
AVR32_USBB.USBSTACLR.vbusrqc = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_SetDeviceAddress(const uint8_t Address)
|
||||
{
|
||||
AVR32_USBB.UHADDR1.uhaddr_p0 = Address;
|
||||
AVR32_USBB.UHADDR1.uhaddr_p1 = Address;
|
||||
AVR32_USBB.UHADDR1.uhaddr_p2 = Address;
|
||||
AVR32_USBB.UHADDR1.uhaddr_p3 = Address;
|
||||
AVR32_USBB.UHADDR2.uhaddr_p4 = Address;
|
||||
AVR32_USBB.UHADDR2.uhaddr_p5 = Address;
|
||||
AVR32_USBB.UHADDR2.uhaddr_p6 = Address;
|
||||
}
|
||||
|
||||
/* Enums: */
|
||||
enum USB_Host_WaitMSErrorCodes_t
|
||||
{
|
||||
HOST_WAITERROR_Successful = 0,
|
||||
HOST_WAITERROR_DeviceDisconnect = 1,
|
||||
HOST_WAITERROR_PipeError = 2,
|
||||
HOST_WAITERROR_SetupStalled = 3,
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
void USB_Host_ProcessNextHostState(void);
|
||||
uint8_t USB_Host_WaitMS(uint8_t MS);
|
||||
|
||||
#if defined(__INCLUDE_FROM_HOST_C)
|
||||
static void USB_Host_ResetDevice(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Host definitions for the AVR32 UC3B microcontrollers.
|
||||
* \copydetails Group_Host_UC3B
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Host
|
||||
* \defgroup Group_Host_UC3B Host Management (UC3B)
|
||||
* \brief USB Host definitions for the AVR32 UC3B microcontrollers.
|
||||
*
|
||||
* Architecture specific USB Host definitions for the Atmel 32-bit AVR UC3B microcontrollers.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBHOST_UC3B_H__
|
||||
#define __USBHOST_UC3B_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../StdDescriptors.h"
|
||||
#include "../Pipe.h"
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Indicates the fixed USB device address which any attached device is enumerated to when in
|
||||
* host mode. As only one USB device may be attached to the AVR in host mode at any one time
|
||||
* and that the address used is not important (other than the fact that it is non-zero), a
|
||||
* fixed value is specified by the library.
|
||||
*/
|
||||
#define USB_HOST_DEVICEADDRESS 1
|
||||
|
||||
#if !defined(USB_HOST_TIMEOUT_MS) || defined(__DOXYGEN__)
|
||||
/** Constant for the maximum software timeout period of sent USB control transactions to an attached
|
||||
* device. If a device fails to respond to a sent control request within this period, the
|
||||
* library will return a timeout error code.
|
||||
*
|
||||
* This value may be overridden in the user project makefile as the value of the
|
||||
* \ref USB_HOST_TIMEOUT_MS token, and passed to the compiler using the -D switch.
|
||||
*/
|
||||
#define USB_HOST_TIMEOUT_MS 1000
|
||||
#endif
|
||||
|
||||
#if !defined(HOST_DEVICE_SETTLE_DELAY_MS) || defined(__DOXYGEN__)
|
||||
/** Constant for the delay in milliseconds after a device is connected before the library
|
||||
* will start the enumeration process. Some devices require a delay of up to 5 seconds
|
||||
* after connection before the enumeration process can start or incorrect operation will
|
||||
* occur.
|
||||
*
|
||||
* The default delay value may be overridden in the user project makefile by defining the
|
||||
* \c HOST_DEVICE_SETTLE_DELAY_MS token to the required delay in milliseconds, and passed to the
|
||||
* compiler using the -D switch.
|
||||
*/
|
||||
#define HOST_DEVICE_SETTLE_DELAY_MS 1000
|
||||
#endif
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the error codes for the \ref EVENT_USB_Host_HostError() event.
|
||||
*
|
||||
* \see \ref Group_Events for more information on this event.
|
||||
*/
|
||||
enum USB_Host_ErrorCodes_t
|
||||
{
|
||||
HOST_ERROR_VBusVoltageDip = 0, /**< VBUS voltage dipped to an unacceptable level. This
|
||||
* error may be the result of an attached device drawing
|
||||
* too much current from the VBUS line, or due to the
|
||||
* AVR's power source being unable to supply sufficient
|
||||
* current.
|
||||
*/
|
||||
};
|
||||
|
||||
/** Enum for the error codes for the \ref EVENT_USB_Host_DeviceEnumerationFailed() event.
|
||||
*
|
||||
* \see \ref Group_Events for more information on this event.
|
||||
*/
|
||||
enum USB_Host_EnumerationErrorCodes_t
|
||||
{
|
||||
HOST_ENUMERROR_NoError = 0, /**< No error occurred. Used internally, this is not a valid
|
||||
* ErrorCode parameter value for the \ref EVENT_USB_Host_DeviceEnumerationFailed()
|
||||
* event.
|
||||
*/
|
||||
HOST_ENUMERROR_WaitStage = 1, /**< One of the delays between enumeration steps failed
|
||||
* to complete successfully, due to a timeout or other
|
||||
* error.
|
||||
*/
|
||||
HOST_ENUMERROR_NoDeviceDetected = 2, /**< No device was detected, despite the USB data lines
|
||||
* indicating the attachment of a device.
|
||||
*/
|
||||
HOST_ENUMERROR_ControlError = 3, /**< One of the enumeration control requests failed to
|
||||
* complete successfully.
|
||||
*/
|
||||
HOST_ENUMERROR_PipeConfigError = 4, /**< The default control pipe (address 0) failed to
|
||||
* configure correctly.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Returns the current USB frame number, when in host mode. Every millisecond the USB bus is active (i.e. not suspended)
|
||||
* the frame number is incremented by one.
|
||||
*/
|
||||
static inline uint16_t USB_Host_GetFrameNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline uint16_t USB_Host_GetFrameNumber(void)
|
||||
{
|
||||
return AVR32_USBB_UHFNUM;
|
||||
}
|
||||
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
/** Enables the host mode Start Of Frame events. When enabled, this causes the
|
||||
* \ref EVENT_USB_Host_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
|
||||
* at the start of each USB frame when a device is enumerated while in host mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Host_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_EnableSOFEvents(void)
|
||||
{
|
||||
USB_INT_Enable(USB_INT_HSOFI);
|
||||
}
|
||||
|
||||
/** Disables the host mode Start Of Frame events. When disabled, this stops the firing of the
|
||||
* \ref EVENT_USB_Host_StartOfFrame() event when enumerated in host mode.
|
||||
*
|
||||
* \note Not available when the NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Host_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_DisableSOFEvents(void)
|
||||
{
|
||||
USB_INT_Disable(USB_INT_HSOFI);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Resets the USB bus, including the endpoints in any attached device and pipes on the AVR host.
|
||||
* USB bus resets leave the default control pipe configured (if already configured).
|
||||
*
|
||||
* If the USB bus has been suspended prior to issuing a bus reset, the attached device will be
|
||||
* woken up automatically and the bus resumed after the reset has been correctly issued.
|
||||
*/
|
||||
static inline void USB_Host_ResetBus(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_ResetBus(void)
|
||||
{
|
||||
AVR32_USBB.UHCON.reset = true;
|
||||
}
|
||||
|
||||
/** Determines if a previously issued bus reset (via the \ref USB_Host_ResetBus() macro) has
|
||||
* completed.
|
||||
*
|
||||
* \return Boolean \c true if no bus reset is currently being sent, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsBusResetComplete(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsBusResetComplete(void)
|
||||
{
|
||||
return AVR32_USBB.UHCON.reset;
|
||||
}
|
||||
|
||||
/** Resumes USB communications with an attached and enumerated device, by resuming the transmission
|
||||
* of the 1MS Start Of Frame messages to the device. When resumed, USB communications between the
|
||||
* host and attached device may occur.
|
||||
*/
|
||||
static inline void USB_Host_ResumeBus(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_ResumeBus(void)
|
||||
{
|
||||
AVR32_USBB.UHCON.sofe = true;
|
||||
}
|
||||
|
||||
/** Suspends the USB bus, preventing any communications from occurring between the host and attached
|
||||
* device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame
|
||||
* messages to the device.
|
||||
*
|
||||
* \note While the USB bus is suspended, all USB interrupt sources are also disabled; this means that
|
||||
* some events (such as device disconnections) will not fire until the bus is resumed.
|
||||
*/
|
||||
static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_SuspendBus(void)
|
||||
{
|
||||
AVR32_USBB.UHCON.sofe = false;
|
||||
}
|
||||
|
||||
/** Determines if the USB bus has been suspended via the use of the \ref USB_Host_SuspendBus() macro,
|
||||
* false otherwise. While suspended, no USB communications can occur until the bus is resumed,
|
||||
* except for the Remote Wakeup event from the device if supported.
|
||||
*
|
||||
* \return Boolean \c true if the bus is currently suspended, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsBusSuspended(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsBusSuspended(void)
|
||||
{
|
||||
return AVR32_USBB.UHCON.sofe;
|
||||
}
|
||||
|
||||
/** Determines if the attached device is currently enumerated in Full Speed mode (12Mb/s), or
|
||||
* false if the attached device is enumerated in Low Speed mode (1.5Mb/s).
|
||||
*
|
||||
* \return Boolean \c true if the attached device is enumerated in Full Speed mode, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsDeviceFullSpeed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsDeviceFullSpeed(void)
|
||||
{
|
||||
return (AVR32_USBB.USBSTA.speed == AVR32_USBB_SPEED_FULL);
|
||||
}
|
||||
|
||||
/** Determines if the attached device is currently issuing a Remote Wakeup request, requesting
|
||||
* that the host resume the USB bus and wake up the device, false otherwise.
|
||||
*
|
||||
* \return Boolean \c true if the attached device has sent a Remote Wakeup request, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsRemoteWakeupSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsRemoteWakeupSent(void)
|
||||
{
|
||||
return AVR32_USBB.UHINT.rxrsmi;
|
||||
}
|
||||
|
||||
/** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */
|
||||
static inline void USB_Host_ClearRemoteWakeupSent(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_ClearRemoteWakeupSent(void)
|
||||
{
|
||||
AVR32_USBB.UHINTCLR.rxrsmic = true;
|
||||
}
|
||||
|
||||
/** Accepts a Remote Wakeup request from an attached device. This must be issued in response to
|
||||
* a device's Remote Wakeup request within 2ms for the request to be accepted and the bus to
|
||||
* be resumed.
|
||||
*/
|
||||
static inline void USB_Host_ResumeFromWakeupRequest(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_ResumeFromWakeupRequest(void)
|
||||
{
|
||||
AVR32_USBB.UHCON.resume = true;
|
||||
}
|
||||
|
||||
/** Determines if a resume from Remote Wakeup request is currently being sent to an attached
|
||||
* device.
|
||||
*
|
||||
* \return Boolean \c true if no resume request is currently being sent, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_Host_IsResumeFromWakeupRequestSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_Host_IsResumeFromWakeupRequestSent(void)
|
||||
{
|
||||
return AVR32_USBB.UHCON.resume;
|
||||
}
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
static inline void USB_Host_HostMode_On(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_HostMode_On(void)
|
||||
{
|
||||
// Not required for UC3B
|
||||
}
|
||||
|
||||
static inline void USB_Host_HostMode_Off(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_HostMode_Off(void)
|
||||
{
|
||||
// Not required for UC3B
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Auto_Enable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Auto_Enable(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.vbushwc = false;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Manual_Enable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Manual_Enable(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.vbushwc = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Auto_On(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Auto_On(void)
|
||||
{
|
||||
AVR32_USBB.USBSTASET.vbusrqs = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Manual_On(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Manual_On(void)
|
||||
{
|
||||
AVR32_USBB.USBSTASET.vbusrqs = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Auto_Off(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Auto_Off(void)
|
||||
{
|
||||
AVR32_USBB.USBSTACLR.vbusrqc = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_VBUS_Manual_Off(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_VBUS_Manual_Off(void)
|
||||
{
|
||||
AVR32_USBB.USBSTACLR.vbusrqc = true;
|
||||
}
|
||||
|
||||
static inline void USB_Host_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Host_SetDeviceAddress(const uint8_t Address)
|
||||
{
|
||||
AVR32_USBB.UHADDR1.uhaddr_p0 = Address;
|
||||
AVR32_USBB.UHADDR1.uhaddr_p1 = Address;
|
||||
AVR32_USBB.UHADDR1.uhaddr_p2 = Address;
|
||||
AVR32_USBB.UHADDR1.uhaddr_p3 = Address;
|
||||
AVR32_USBB.UHADDR2.uhaddr_p4 = Address;
|
||||
AVR32_USBB.UHADDR2.uhaddr_p5 = Address;
|
||||
AVR32_USBB.UHADDR2.uhaddr_p6 = Address;
|
||||
}
|
||||
|
||||
/* Enums: */
|
||||
enum USB_Host_WaitMSErrorCodes_t
|
||||
{
|
||||
HOST_WAITERROR_Successful = 0,
|
||||
HOST_WAITERROR_DeviceDisconnect = 1,
|
||||
HOST_WAITERROR_PipeError = 2,
|
||||
HOST_WAITERROR_SetupStalled = 3,
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
void USB_Host_ProcessNextHostState(void);
|
||||
uint8_t USB_Host_WaitMS(uint8_t MS);
|
||||
|
||||
#if defined(__INCLUDE_FROM_HOST_C)
|
||||
static void USB_Host_ResetDevice(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,138 +1,138 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#include "../Pipe.h"
|
||||
|
||||
uint8_t USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
|
||||
|
||||
volatile uint32_t USB_SelectedPipe = PIPE_CONTROLPIPE;
|
||||
volatile uint8_t* USB_PipeFIFOPos[PIPE_TOTAL_PIPES];
|
||||
|
||||
bool Pipe_ConfigurePipe(const uint8_t Number,
|
||||
const uint8_t Type,
|
||||
const uint8_t Token,
|
||||
const uint8_t EndpointNumber,
|
||||
const uint16_t Size,
|
||||
const uint8_t Banks)
|
||||
{
|
||||
Pipe_SelectPipe(Number);
|
||||
Pipe_EnablePipe();
|
||||
|
||||
(&AVR32_USBB.upcfg0)[Number] = 0;
|
||||
(&AVR32_USBB.upcfg0)[Number] = (AVR32_USBB_ALLOC_MASK |
|
||||
((uint32_t)Type << AVR32_USBB_PTYPE_OFFSET) |
|
||||
((uint32_t)Token << AVR32_USBB_PTOKEN_OFFSET) |
|
||||
((uint32_t)Banks << AVR32_USBB_PBK_OFFSET) |
|
||||
((EndpointNumber & PIPE_EPNUM_MASK) << AVR32_USBB_PEPNUM_OFFSET));
|
||||
USB_PipeFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000];
|
||||
|
||||
Pipe_SetInfiniteINRequests();
|
||||
|
||||
return Pipe_IsConfigured();
|
||||
}
|
||||
|
||||
void Pipe_ClearPipes(void)
|
||||
{
|
||||
for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
|
||||
{
|
||||
Pipe_SelectPipe(PNum);
|
||||
(&AVR32_USBB.upcfg0)[PNum] = 0;
|
||||
(&AVR32_USBB.upcon0clr)[PNum] = -1;
|
||||
USB_PipeFIFOPos[PNum] = &AVR32_USBB_SLAVE[PNum * 0x10000];
|
||||
Pipe_DisablePipe();
|
||||
}
|
||||
}
|
||||
|
||||
bool Pipe_IsEndpointBound(const uint8_t EndpointAddress)
|
||||
{
|
||||
uint8_t PrevPipeNumber = Pipe_GetCurrentPipe();
|
||||
|
||||
for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
|
||||
{
|
||||
Pipe_SelectPipe(PNum);
|
||||
|
||||
if (!(Pipe_IsConfigured()))
|
||||
continue;
|
||||
|
||||
if (Pipe_GetBoundEndpointAddress() == EndpointAddress)
|
||||
return true;
|
||||
}
|
||||
|
||||
Pipe_SelectPipe(PrevPipeNumber);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t Pipe_WaitUntilReady(void)
|
||||
{
|
||||
#if (USB_STREAM_TIMEOUT_MS < 0xFF)
|
||||
uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
|
||||
#else
|
||||
uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
|
||||
#endif
|
||||
|
||||
uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
|
||||
{
|
||||
if (Pipe_IsINReceived())
|
||||
return PIPE_READYWAIT_NoError;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Pipe_IsOUTReady())
|
||||
return PIPE_READYWAIT_NoError;
|
||||
}
|
||||
|
||||
if (Pipe_IsStalled())
|
||||
return PIPE_READYWAIT_PipeStalled;
|
||||
else if (USB_HostState == HOST_STATE_Unattached)
|
||||
return PIPE_READYWAIT_DeviceDisconnected;
|
||||
|
||||
uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();
|
||||
|
||||
if (CurrentFrameNumber != PreviousFrameNumber)
|
||||
{
|
||||
PreviousFrameNumber = CurrentFrameNumber;
|
||||
|
||||
if (!(TimeoutMSRem--))
|
||||
return PIPE_READYWAIT_Timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#include "../Pipe.h"
|
||||
|
||||
uint8_t USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
|
||||
|
||||
volatile uint32_t USB_SelectedPipe = PIPE_CONTROLPIPE;
|
||||
volatile uint8_t* USB_PipeFIFOPos[PIPE_TOTAL_PIPES];
|
||||
|
||||
bool Pipe_ConfigurePipe(const uint8_t Number,
|
||||
const uint8_t Type,
|
||||
const uint8_t Token,
|
||||
const uint8_t EndpointNumber,
|
||||
const uint16_t Size,
|
||||
const uint8_t Banks)
|
||||
{
|
||||
Pipe_SelectPipe(Number);
|
||||
Pipe_EnablePipe();
|
||||
|
||||
(&AVR32_USBB.upcfg0)[Number] = 0;
|
||||
(&AVR32_USBB.upcfg0)[Number] = (AVR32_USBB_ALLOC_MASK |
|
||||
((uint32_t)Type << AVR32_USBB_PTYPE_OFFSET) |
|
||||
((uint32_t)Token << AVR32_USBB_PTOKEN_OFFSET) |
|
||||
((uint32_t)Banks << AVR32_USBB_PBK_OFFSET) |
|
||||
((EndpointNumber & PIPE_EPNUM_MASK) << AVR32_USBB_PEPNUM_OFFSET));
|
||||
USB_PipeFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000];
|
||||
|
||||
Pipe_SetInfiniteINRequests();
|
||||
|
||||
return Pipe_IsConfigured();
|
||||
}
|
||||
|
||||
void Pipe_ClearPipes(void)
|
||||
{
|
||||
for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
|
||||
{
|
||||
Pipe_SelectPipe(PNum);
|
||||
(&AVR32_USBB.upcfg0)[PNum] = 0;
|
||||
(&AVR32_USBB.upcon0clr)[PNum] = -1;
|
||||
USB_PipeFIFOPos[PNum] = &AVR32_USBB_SLAVE[PNum * 0x10000];
|
||||
Pipe_DisablePipe();
|
||||
}
|
||||
}
|
||||
|
||||
bool Pipe_IsEndpointBound(const uint8_t EndpointAddress)
|
||||
{
|
||||
uint8_t PrevPipeNumber = Pipe_GetCurrentPipe();
|
||||
|
||||
for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
|
||||
{
|
||||
Pipe_SelectPipe(PNum);
|
||||
|
||||
if (!(Pipe_IsConfigured()))
|
||||
continue;
|
||||
|
||||
if (Pipe_GetBoundEndpointAddress() == EndpointAddress)
|
||||
return true;
|
||||
}
|
||||
|
||||
Pipe_SelectPipe(PrevPipeNumber);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t Pipe_WaitUntilReady(void)
|
||||
{
|
||||
#if (USB_STREAM_TIMEOUT_MS < 0xFF)
|
||||
uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
|
||||
#else
|
||||
uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
|
||||
#endif
|
||||
|
||||
uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
|
||||
{
|
||||
if (Pipe_IsINReceived())
|
||||
return PIPE_READYWAIT_NoError;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Pipe_IsOUTReady())
|
||||
return PIPE_READYWAIT_NoError;
|
||||
}
|
||||
|
||||
if (Pipe_IsStalled())
|
||||
return PIPE_READYWAIT_PipeStalled;
|
||||
else if (USB_HostState == HOST_STATE_Unattached)
|
||||
return PIPE_READYWAIT_DeviceDisconnected;
|
||||
|
||||
uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();
|
||||
|
||||
if (CurrentFrameNumber != PreviousFrameNumber)
|
||||
{
|
||||
PreviousFrameNumber = CurrentFrameNumber;
|
||||
|
||||
if (!(TimeoutMSRem--))
|
||||
return PIPE_READYWAIT_Timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,215 +1,215 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#define __INCLUDE_FROM_USB_CONTROLLER_C
|
||||
#include "../USBController.h"
|
||||
|
||||
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY))
|
||||
volatile uint8_t USB_CurrentMode = USB_MODE_None;
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
volatile uint8_t USB_Options;
|
||||
#endif
|
||||
|
||||
void USB_Init(
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
const uint8_t Mode
|
||||
#endif
|
||||
|
||||
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS))
|
||||
,
|
||||
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
|
||||
void
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
const uint8_t Options
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
USB_Options = Options;
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
if (Mode == USB_MODE_UID)
|
||||
{
|
||||
AVR32_USBB.USBCON.uide = true;
|
||||
USB_INT_Enable(USB_INT_IDTI);
|
||||
USB_CurrentMode = USB_GetUSBModeFromUID();
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR32_USBB.USBCON.uide = false;
|
||||
USB_CurrentMode = Mode;
|
||||
}
|
||||
#else
|
||||
AVR32_USBB.USBCON.uide = false;
|
||||
#endif
|
||||
|
||||
USB_IsInitialized = true;
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
|
||||
void USB_Disable(void)
|
||||
{
|
||||
USB_INT_DisableAllInterrupts();
|
||||
USB_INT_ClearAllInterrupts();
|
||||
|
||||
USB_Detach();
|
||||
USB_Controller_Disable();
|
||||
|
||||
USB_OTGPAD_Off();
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
USB_CurrentMode = USB_MODE_None;
|
||||
#endif
|
||||
|
||||
AVR32_PM.GCCTRL[3].cen = false;
|
||||
|
||||
USB_IsInitialized = false;
|
||||
}
|
||||
|
||||
void USB_ResetInterface(void)
|
||||
{
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
bool UIDModeSelectEnabled = AVR32_USBB.USBCON.uide;
|
||||
#endif
|
||||
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].pllsel = !(USB_Options & USB_OPT_GCLK_SRC_OSC);
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].oscsel = !(USB_Options & USB_OPT_GCLK_CHANNEL_0);
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].diven = (F_USB != USB_CLOCK_REQUIRED_FREQ);
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].div = (F_USB == USB_CLOCK_REQUIRED_FREQ) ? 0 : (uint32_t)(((F_USB / USB_CLOCK_REQUIRED_FREQ) - 1) / 2);
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].cen = true;
|
||||
|
||||
USB_INT_DisableAllInterrupts();
|
||||
USB_INT_ClearAllInterrupts();
|
||||
|
||||
USB_Controller_Reset();
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
if (UIDModeSelectEnabled)
|
||||
USB_INT_Enable(USB_INT_IDTI);
|
||||
#endif
|
||||
|
||||
USB_CLK_Unfreeze();
|
||||
|
||||
if (USB_CurrentMode == USB_MODE_Device)
|
||||
{
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
AVR32_USBB.USBCON.uimod = true;
|
||||
|
||||
USB_Init_Device();
|
||||
#endif
|
||||
}
|
||||
else if (USB_CurrentMode == USB_MODE_Host)
|
||||
{
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
AVR32_USBB.USBCON.uimod = false;
|
||||
|
||||
USB_Init_Host();
|
||||
#endif
|
||||
}
|
||||
|
||||
USB_OTGPAD_On();
|
||||
}
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
static void USB_Init_Device(void)
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
USB_Device_ConfigurationNumber = 0;
|
||||
|
||||
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
|
||||
USB_Device_RemoteWakeupEnabled = false;
|
||||
#endif
|
||||
|
||||
#if !defined(NO_DEVICE_SELF_POWER)
|
||||
USB_Device_CurrentlySelfPowered = false;
|
||||
#endif
|
||||
|
||||
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
|
||||
USB_Descriptor_Device_t* DeviceDescriptorPtr;
|
||||
|
||||
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)
|
||||
USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
|
||||
#endif
|
||||
|
||||
if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
|
||||
{
|
||||
USB_Device_SetLowSpeed();
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(USB_DEVICE_OPT_HIGHSPEED)
|
||||
if (USB_Options & USB_DEVICE_OPT_HIGHSPEED)
|
||||
USB_Device_SetHighSpeed();
|
||||
else
|
||||
USB_Device_SetFullSpeed();
|
||||
#else
|
||||
USB_Device_SetFullSpeed();
|
||||
#endif
|
||||
}
|
||||
|
||||
USB_INT_Enable(USB_INT_VBUSTI);
|
||||
|
||||
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
|
||||
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
USB_INT_Clear(USB_INT_SUSPI);
|
||||
USB_INT_Enable(USB_INT_SUSPI);
|
||||
USB_INT_Enable(USB_INT_EORSTI);
|
||||
|
||||
USB_Attach();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
static void USB_Init_Host(void)
|
||||
{
|
||||
USB_HostState = HOST_STATE_Unattached;
|
||||
USB_Host_ConfigurationNumber = 0;
|
||||
USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
|
||||
|
||||
USB_Host_HostMode_On();
|
||||
|
||||
USB_Host_VBUS_Auto_On();
|
||||
|
||||
USB_INT_Enable(USB_INT_DCONNI);
|
||||
USB_INT_Enable(USB_INT_BCERRI);
|
||||
|
||||
USB_Attach();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#define __INCLUDE_FROM_USB_CONTROLLER_C
|
||||
#include "../USBController.h"
|
||||
|
||||
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY))
|
||||
volatile uint8_t USB_CurrentMode = USB_MODE_None;
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
volatile uint8_t USB_Options;
|
||||
#endif
|
||||
|
||||
void USB_Init(
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
const uint8_t Mode
|
||||
#endif
|
||||
|
||||
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS))
|
||||
,
|
||||
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
|
||||
void
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
const uint8_t Options
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
USB_Options = Options;
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
if (Mode == USB_MODE_UID)
|
||||
{
|
||||
AVR32_USBB.USBCON.uide = true;
|
||||
USB_INT_Enable(USB_INT_IDTI);
|
||||
USB_CurrentMode = USB_GetUSBModeFromUID();
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR32_USBB.USBCON.uide = false;
|
||||
USB_CurrentMode = Mode;
|
||||
}
|
||||
#else
|
||||
AVR32_USBB.USBCON.uide = false;
|
||||
#endif
|
||||
|
||||
USB_IsInitialized = true;
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
|
||||
void USB_Disable(void)
|
||||
{
|
||||
USB_INT_DisableAllInterrupts();
|
||||
USB_INT_ClearAllInterrupts();
|
||||
|
||||
USB_Detach();
|
||||
USB_Controller_Disable();
|
||||
|
||||
USB_OTGPAD_Off();
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
USB_CurrentMode = USB_MODE_None;
|
||||
#endif
|
||||
|
||||
AVR32_PM.GCCTRL[3].cen = false;
|
||||
|
||||
USB_IsInitialized = false;
|
||||
}
|
||||
|
||||
void USB_ResetInterface(void)
|
||||
{
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
bool UIDModeSelectEnabled = AVR32_USBB.USBCON.uide;
|
||||
#endif
|
||||
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].pllsel = !(USB_Options & USB_OPT_GCLK_SRC_OSC);
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].oscsel = !(USB_Options & USB_OPT_GCLK_CHANNEL_0);
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].diven = (F_USB != USB_CLOCK_REQUIRED_FREQ);
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].div = (F_USB == USB_CLOCK_REQUIRED_FREQ) ? 0 : (uint32_t)(((F_USB / USB_CLOCK_REQUIRED_FREQ) - 1) / 2);
|
||||
AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].cen = true;
|
||||
|
||||
USB_INT_DisableAllInterrupts();
|
||||
USB_INT_ClearAllInterrupts();
|
||||
|
||||
USB_Controller_Reset();
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
if (UIDModeSelectEnabled)
|
||||
USB_INT_Enable(USB_INT_IDTI);
|
||||
#endif
|
||||
|
||||
USB_CLK_Unfreeze();
|
||||
|
||||
if (USB_CurrentMode == USB_MODE_Device)
|
||||
{
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
AVR32_USBB.USBCON.uimod = true;
|
||||
|
||||
USB_Init_Device();
|
||||
#endif
|
||||
}
|
||||
else if (USB_CurrentMode == USB_MODE_Host)
|
||||
{
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
AVR32_USBB.USBCON.uimod = false;
|
||||
|
||||
USB_Init_Host();
|
||||
#endif
|
||||
}
|
||||
|
||||
USB_OTGPAD_On();
|
||||
}
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
static void USB_Init_Device(void)
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
USB_Device_ConfigurationNumber = 0;
|
||||
|
||||
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
|
||||
USB_Device_RemoteWakeupEnabled = false;
|
||||
#endif
|
||||
|
||||
#if !defined(NO_DEVICE_SELF_POWER)
|
||||
USB_Device_CurrentlySelfPowered = false;
|
||||
#endif
|
||||
|
||||
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
|
||||
USB_Descriptor_Device_t* DeviceDescriptorPtr;
|
||||
|
||||
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)
|
||||
USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
|
||||
#endif
|
||||
|
||||
if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
|
||||
{
|
||||
USB_Device_SetLowSpeed();
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(USB_DEVICE_OPT_HIGHSPEED)
|
||||
if (USB_Options & USB_DEVICE_OPT_HIGHSPEED)
|
||||
USB_Device_SetHighSpeed();
|
||||
else
|
||||
USB_Device_SetFullSpeed();
|
||||
#else
|
||||
USB_Device_SetFullSpeed();
|
||||
#endif
|
||||
}
|
||||
|
||||
USB_INT_Enable(USB_INT_VBUSTI);
|
||||
|
||||
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
|
||||
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
USB_INT_Clear(USB_INT_SUSPI);
|
||||
USB_INT_Enable(USB_INT_SUSPI);
|
||||
USB_INT_Enable(USB_INT_EORSTI);
|
||||
|
||||
USB_Attach();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
static void USB_Init_Host(void)
|
||||
{
|
||||
USB_HostState = HOST_STATE_Unattached;
|
||||
USB_Host_ConfigurationNumber = 0;
|
||||
USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
|
||||
|
||||
USB_Host_HostMode_On();
|
||||
|
||||
USB_Host_VBUS_Auto_On();
|
||||
|
||||
USB_INT_Enable(USB_INT_DCONNI);
|
||||
USB_INT_Enable(USB_INT_BCERRI);
|
||||
|
||||
USB_Attach();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,383 +1,383 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Controller definitions for the AVR32 UC3 microcontrollers.
|
||||
* \copydetails Group_USBManagement_UC3
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USBManagement
|
||||
* \defgroup Group_USBManagement_UC3 USB Interface Management (UC3)
|
||||
* \brief USB Controller definitions for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the setup and management of the USB interface.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBCONTROLLER_UC3_H__
|
||||
#define __USBCONTROLLER_UC3_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../USBMode.h"
|
||||
#include "../Events.h"
|
||||
#include "../USBTask.h"
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
|
||||
#include "../Host.h"
|
||||
#include "../OTG.h"
|
||||
#include "../Pipe.h"
|
||||
#include "../HostStandardReq.h"
|
||||
#include "../PipeStream.h"
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
|
||||
#include "../Device.h"
|
||||
#include "../Endpoint.h"
|
||||
#include "../DeviceStandardReq.h"
|
||||
#include "../EndpointStream.h"
|
||||
#endif
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks and Defines: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
#if !defined(F_USB)
|
||||
#error F_USB is not defined. You must define F_USB to the frequency of the clock input to the USB module.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name USB Controller Option Masks */
|
||||
//@{
|
||||
/** Selects one of the system's main clock oscillators as the input clock to the USB Generic Clock source
|
||||
* generation module. This indicates that an external oscillator should be used directly instead of an
|
||||
* internal PLL clock source.
|
||||
*/
|
||||
#define USB_OPT_GCLK_SRC_OSC (1 << 2)
|
||||
|
||||
/** Selects one of the system's PLL oscillators as the input clock to the USB Generic Clock source
|
||||
* generation module. This indicates that one of the device's PLL outputs should be used instead of an
|
||||
* external oscillator source.
|
||||
*/
|
||||
#define USB_OPT_GCLK_SRC_PLL (0 << 2)
|
||||
|
||||
/** Selects PLL or External Oscillator 0 as the USB Generic Clock source module input clock. */
|
||||
#define USB_OPT_GCLK_CHANNEL_0 (1 << 3)
|
||||
|
||||
/** Selects PLL or External Oscillator 1 as the USB Generic Clock source module input clock. */
|
||||
#define USB_OPT_GCLK_CHANNEL_1 (0 << 3)
|
||||
//@}
|
||||
|
||||
/** \name Endpoint/Pipe Type Masks */
|
||||
//@{
|
||||
/** Mask for a CONTROL type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_CONTROL 0x00
|
||||
|
||||
/** Mask for an ISOCHRONOUS type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_ISOCHRONOUS 0x01
|
||||
|
||||
/** Mask for a BULK type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_BULK 0x02
|
||||
|
||||
/** Mask for an INTERRUPT type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_INTERRUPT 0x03
|
||||
//@}
|
||||
|
||||
#if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)
|
||||
/** Constant for the maximum software timeout period of the USB data stream transfer functions
|
||||
* (both control and standard) when in either device or host mode. If the next packet of a stream
|
||||
* is not received or acknowledged within this time period, the stream function will fail.
|
||||
*
|
||||
* This value may be overridden in the user project makefile as the value of the
|
||||
* \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch.
|
||||
*/
|
||||
#define USB_STREAM_TIMEOUT_MS 100
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Determines if the VBUS line is currently high (i.e. the USB host is supplying power).
|
||||
*
|
||||
* \return Boolean \c true if the VBUS line is currently detecting power from a host, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_VBUS_GetStatus(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_VBUS_GetStatus(void)
|
||||
{
|
||||
return AVR32_USBB.USBSTA.vbus;
|
||||
}
|
||||
|
||||
/** Detaches the device from the USB bus. This has the effect of removing the device from any
|
||||
* attached host, ceasing USB communications. If no host is present, this prevents any host from
|
||||
* enumerating the device once attached until \ref USB_Attach() is called.
|
||||
*/
|
||||
static inline void USB_Detach(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Detach(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.detach = true;
|
||||
}
|
||||
|
||||
/** Attaches the device to the USB bus. This announces the device's presence to any attached
|
||||
* USB host, starting the enumeration process. If no host is present, attaching the device
|
||||
* will allow for enumeration once a host is connected to the device.
|
||||
*
|
||||
* This is inexplicably also required for proper operation while in host mode, to enable the
|
||||
* attachment of a device to the host. This is despite the bit being located in the device-mode
|
||||
* register and despite the datasheet making no mention of its requirement in host mode.
|
||||
*/
|
||||
static inline void USB_Attach(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Attach(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.detach = false;
|
||||
}
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Main function to initialize and start the USB interface. Once active, the USB interface will
|
||||
* allow for device connection to a host when in device mode, or for device enumeration while in
|
||||
* host mode.
|
||||
*
|
||||
* As the USB library relies on interrupts for the device and host mode enumeration processes,
|
||||
* the user must enable global interrupts before or shortly after this function is called. In
|
||||
* device mode, interrupts must be enabled within 500ms of this function being called to ensure
|
||||
* that the host does not time out whilst enumerating the device. In host mode, interrupts may be
|
||||
* enabled at the application's leisure however enumeration will not begin of an attached device
|
||||
* until after this has occurred.
|
||||
*
|
||||
* Calling this function when the USB interface is already initialized will cause a complete USB
|
||||
* interface reset and re-enumeration.
|
||||
*
|
||||
* \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to, a value
|
||||
* from the \ref USB_Modes_t enum.
|
||||
*
|
||||
* \param[in] Options Mask indicating the options which should be used when initializing the USB
|
||||
* interface to control the USB interface's behaviour. This should be comprised of
|
||||
* a \c USB_OPT_REG_* mask to control the regulator, a \c USB_OPT_*_PLL mask to control the
|
||||
* PLL, and a \c USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device
|
||||
* mode speed.
|
||||
*
|
||||
* \note To reduce the FLASH requirements of the library if only device or host mode is required,
|
||||
* the mode can be statically set in the project makefile by defining the token \c USB_DEVICE_ONLY
|
||||
* (for device mode) or \c USB_HOST_ONLY (for host mode), passing the token to the compiler
|
||||
* via the -D switch. If the mode is statically set, this parameter does not exist in the
|
||||
* function prototype.
|
||||
* \n\n
|
||||
*
|
||||
* \note To reduce the FLASH requirements of the library if only fixed settings are are required,
|
||||
* the options may be set statically in the same manner as the mode (see the Mode parameter of
|
||||
* this function). To statically set the USB options, pass in the \c USE_STATIC_OPTIONS token,
|
||||
* defined to the appropriate options masks. When the options are statically set, this
|
||||
* parameter does not exist in the function prototype.
|
||||
*
|
||||
* \see \ref Group_Device for the \c USB_DEVICE_OPT_* masks.
|
||||
*/
|
||||
void USB_Init(
|
||||
#if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
|
||||
const uint8_t Mode
|
||||
#endif
|
||||
|
||||
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__)
|
||||
,
|
||||
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
|
||||
void
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
|
||||
const uint8_t Options
|
||||
#endif
|
||||
);
|
||||
|
||||
/** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO
|
||||
* memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface
|
||||
* is restarted with the \ref USB_Init() function.
|
||||
*/
|
||||
void USB_Disable(void);
|
||||
|
||||
/** Resets the interface, when already initialized. This will re-enumerate the device if already connected
|
||||
* to a host, or re-enumerate an already attached device when in host mode.
|
||||
*/
|
||||
void USB_ResetInterface(void);
|
||||
|
||||
/* Global Variables: */
|
||||
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__)
|
||||
/** Indicates the mode that the USB interface is currently initialized to, a value from the
|
||||
* \ref USB_Modes_t enum.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
* \n\n
|
||||
*
|
||||
* \note When the controller is initialized into UID auto-detection mode, this variable will hold the
|
||||
* currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller
|
||||
* is fixed into a specific mode (either through the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY compile time
|
||||
* options, or a limitation of the USB controller in the chosen device model) this will evaluate to
|
||||
* a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the
|
||||
* USB interface is not initialized.
|
||||
*/
|
||||
extern volatile uint8_t USB_CurrentMode;
|
||||
#elif defined(USB_HOST_ONLY)
|
||||
#define USB_CurrentMode USB_MODE_Host
|
||||
#elif defined(USB_DEVICE_ONLY)
|
||||
#define USB_CurrentMode USB_MODE_Device
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
|
||||
/** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init()
|
||||
* was called. This value will be one of the \c USB_MODE_* masks defined elsewhere in this module.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
*/
|
||||
extern volatile uint8_t USB_Options;
|
||||
#elif defined(USE_STATIC_OPTIONS)
|
||||
#define USB_Options USE_STATIC_OPTIONS
|
||||
#endif
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible USB controller modes, for initialization via \ref USB_Init() and indication back to the
|
||||
* user application via \ref USB_CurrentMode.
|
||||
*/
|
||||
enum USB_Modes_t
|
||||
{
|
||||
USB_MODE_None = 0, /**< Indicates that the controller is currently not initialized in any specific USB mode. */
|
||||
USB_MODE_Device = 1, /**< Indicates that the controller is currently initialized in USB Device mode. */
|
||||
USB_MODE_Host = 2, /**< Indicates that the controller is currently initialized in USB Host mode. */
|
||||
USB_MODE_UID = 3, /**< Indicates that the controller should determine the USB mode from the UID pin of the
|
||||
* USB connector.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#if defined(USB_SERIES_UC3A3_AVR32) || defined(USB_SERIES_UC3A4_AVR32)
|
||||
#define USB_CLOCK_REQUIRED_FREQ 12000000UL
|
||||
#else
|
||||
#define USB_CLOCK_REQUIRED_FREQ 48000000UL
|
||||
#endif
|
||||
|
||||
/* Function Prototypes: */
|
||||
#if defined(__INCLUDE_FROM_USB_CONTROLLER_C)
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
static void USB_Init_Device(void);
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
static void USB_Init_Host(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
static inline void USB_OTGPAD_On(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_OTGPAD_On(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.otgpade = true;
|
||||
}
|
||||
|
||||
static inline void USB_OTGPAD_Off(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_OTGPAD_Off(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.otgpade = false;
|
||||
}
|
||||
|
||||
static inline void USB_CLK_Freeze(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_CLK_Freeze(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.frzclk = true;
|
||||
}
|
||||
|
||||
static inline void USB_CLK_Unfreeze(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_CLK_Unfreeze(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.frzclk = false;
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Enable(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.usbe = true;
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Disable(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.usbe = false;
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Reset(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Reset(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.usbe = false;
|
||||
AVR32_USBB.USBCON.usbe = true;
|
||||
}
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline uint8_t USB_GetUSBModeFromUID(void)
|
||||
{
|
||||
if (AVR32_USBB.USBSTA.id)
|
||||
return USB_MODE_Device;
|
||||
else
|
||||
return USB_MODE_Host;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Controller definitions for the AVR32 UC3 microcontrollers.
|
||||
* \copydetails Group_USBManagement_UC3
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USBManagement
|
||||
* \defgroup Group_USBManagement_UC3 USB Interface Management (UC3)
|
||||
* \brief USB Controller definitions for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the setup and management of the USB interface.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBCONTROLLER_UC3_H__
|
||||
#define __USBCONTROLLER_UC3_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../USBMode.h"
|
||||
#include "../Events.h"
|
||||
#include "../USBTask.h"
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
|
||||
#include "../Host.h"
|
||||
#include "../OTG.h"
|
||||
#include "../Pipe.h"
|
||||
#include "../HostStandardReq.h"
|
||||
#include "../PipeStream.h"
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
|
||||
#include "../Device.h"
|
||||
#include "../Endpoint.h"
|
||||
#include "../DeviceStandardReq.h"
|
||||
#include "../EndpointStream.h"
|
||||
#endif
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks and Defines: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
#if !defined(F_USB)
|
||||
#error F_USB is not defined. You must define F_USB to the frequency of the clock input to the USB module.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name USB Controller Option Masks */
|
||||
//@{
|
||||
/** Selects one of the system's main clock oscillators as the input clock to the USB Generic Clock source
|
||||
* generation module. This indicates that an external oscillator should be used directly instead of an
|
||||
* internal PLL clock source.
|
||||
*/
|
||||
#define USB_OPT_GCLK_SRC_OSC (1 << 2)
|
||||
|
||||
/** Selects one of the system's PLL oscillators as the input clock to the USB Generic Clock source
|
||||
* generation module. This indicates that one of the device's PLL outputs should be used instead of an
|
||||
* external oscillator source.
|
||||
*/
|
||||
#define USB_OPT_GCLK_SRC_PLL (0 << 2)
|
||||
|
||||
/** Selects PLL or External Oscillator 0 as the USB Generic Clock source module input clock. */
|
||||
#define USB_OPT_GCLK_CHANNEL_0 (1 << 3)
|
||||
|
||||
/** Selects PLL or External Oscillator 1 as the USB Generic Clock source module input clock. */
|
||||
#define USB_OPT_GCLK_CHANNEL_1 (0 << 3)
|
||||
//@}
|
||||
|
||||
/** \name Endpoint/Pipe Type Masks */
|
||||
//@{
|
||||
/** Mask for a CONTROL type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_CONTROL 0x00
|
||||
|
||||
/** Mask for an ISOCHRONOUS type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_ISOCHRONOUS 0x01
|
||||
|
||||
/** Mask for a BULK type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_BULK 0x02
|
||||
|
||||
/** Mask for an INTERRUPT type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_INTERRUPT 0x03
|
||||
//@}
|
||||
|
||||
#if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)
|
||||
/** Constant for the maximum software timeout period of the USB data stream transfer functions
|
||||
* (both control and standard) when in either device or host mode. If the next packet of a stream
|
||||
* is not received or acknowledged within this time period, the stream function will fail.
|
||||
*
|
||||
* This value may be overridden in the user project makefile as the value of the
|
||||
* \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch.
|
||||
*/
|
||||
#define USB_STREAM_TIMEOUT_MS 100
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Determines if the VBUS line is currently high (i.e. the USB host is supplying power).
|
||||
*
|
||||
* \return Boolean \c true if the VBUS line is currently detecting power from a host, \c false otherwise.
|
||||
*/
|
||||
static inline bool USB_VBUS_GetStatus(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline bool USB_VBUS_GetStatus(void)
|
||||
{
|
||||
return AVR32_USBB.USBSTA.vbus;
|
||||
}
|
||||
|
||||
/** Detaches the device from the USB bus. This has the effect of removing the device from any
|
||||
* attached host, ceasing USB communications. If no host is present, this prevents any host from
|
||||
* enumerating the device once attached until \ref USB_Attach() is called.
|
||||
*/
|
||||
static inline void USB_Detach(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Detach(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.detach = true;
|
||||
}
|
||||
|
||||
/** Attaches the device to the USB bus. This announces the device's presence to any attached
|
||||
* USB host, starting the enumeration process. If no host is present, attaching the device
|
||||
* will allow for enumeration once a host is connected to the device.
|
||||
*
|
||||
* This is inexplicably also required for proper operation while in host mode, to enable the
|
||||
* attachment of a device to the host. This is despite the bit being located in the device-mode
|
||||
* register and despite the datasheet making no mention of its requirement in host mode.
|
||||
*/
|
||||
static inline void USB_Attach(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Attach(void)
|
||||
{
|
||||
AVR32_USBB.UDCON.detach = false;
|
||||
}
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Main function to initialize and start the USB interface. Once active, the USB interface will
|
||||
* allow for device connection to a host when in device mode, or for device enumeration while in
|
||||
* host mode.
|
||||
*
|
||||
* As the USB library relies on interrupts for the device and host mode enumeration processes,
|
||||
* the user must enable global interrupts before or shortly after this function is called. In
|
||||
* device mode, interrupts must be enabled within 500ms of this function being called to ensure
|
||||
* that the host does not time out whilst enumerating the device. In host mode, interrupts may be
|
||||
* enabled at the application's leisure however enumeration will not begin of an attached device
|
||||
* until after this has occurred.
|
||||
*
|
||||
* Calling this function when the USB interface is already initialized will cause a complete USB
|
||||
* interface reset and re-enumeration.
|
||||
*
|
||||
* \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to, a value
|
||||
* from the \ref USB_Modes_t enum.
|
||||
*
|
||||
* \param[in] Options Mask indicating the options which should be used when initializing the USB
|
||||
* interface to control the USB interface's behaviour. This should be comprised of
|
||||
* a \c USB_OPT_REG_* mask to control the regulator, a \c USB_OPT_*_PLL mask to control the
|
||||
* PLL, and a \c USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device
|
||||
* mode speed.
|
||||
*
|
||||
* \note To reduce the FLASH requirements of the library if only device or host mode is required,
|
||||
* the mode can be statically set in the project makefile by defining the token \c USB_DEVICE_ONLY
|
||||
* (for device mode) or \c USB_HOST_ONLY (for host mode), passing the token to the compiler
|
||||
* via the -D switch. If the mode is statically set, this parameter does not exist in the
|
||||
* function prototype.
|
||||
* \n\n
|
||||
*
|
||||
* \note To reduce the FLASH requirements of the library if only fixed settings are are required,
|
||||
* the options may be set statically in the same manner as the mode (see the Mode parameter of
|
||||
* this function). To statically set the USB options, pass in the \c USE_STATIC_OPTIONS token,
|
||||
* defined to the appropriate options masks. When the options are statically set, this
|
||||
* parameter does not exist in the function prototype.
|
||||
*
|
||||
* \see \ref Group_Device for the \c USB_DEVICE_OPT_* masks.
|
||||
*/
|
||||
void USB_Init(
|
||||
#if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
|
||||
const uint8_t Mode
|
||||
#endif
|
||||
|
||||
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__)
|
||||
,
|
||||
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
|
||||
void
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
|
||||
const uint8_t Options
|
||||
#endif
|
||||
);
|
||||
|
||||
/** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO
|
||||
* memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface
|
||||
* is restarted with the \ref USB_Init() function.
|
||||
*/
|
||||
void USB_Disable(void);
|
||||
|
||||
/** Resets the interface, when already initialized. This will re-enumerate the device if already connected
|
||||
* to a host, or re-enumerate an already attached device when in host mode.
|
||||
*/
|
||||
void USB_ResetInterface(void);
|
||||
|
||||
/* Global Variables: */
|
||||
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__)
|
||||
/** Indicates the mode that the USB interface is currently initialized to, a value from the
|
||||
* \ref USB_Modes_t enum.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
* \n\n
|
||||
*
|
||||
* \note When the controller is initialized into UID auto-detection mode, this variable will hold the
|
||||
* currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller
|
||||
* is fixed into a specific mode (either through the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY compile time
|
||||
* options, or a limitation of the USB controller in the chosen device model) this will evaluate to
|
||||
* a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the
|
||||
* USB interface is not initialized.
|
||||
*/
|
||||
extern volatile uint8_t USB_CurrentMode;
|
||||
#elif defined(USB_HOST_ONLY)
|
||||
#define USB_CurrentMode USB_MODE_Host
|
||||
#elif defined(USB_DEVICE_ONLY)
|
||||
#define USB_CurrentMode USB_MODE_Device
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
|
||||
/** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init()
|
||||
* was called. This value will be one of the \c USB_MODE_* masks defined elsewhere in this module.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
*/
|
||||
extern volatile uint8_t USB_Options;
|
||||
#elif defined(USE_STATIC_OPTIONS)
|
||||
#define USB_Options USE_STATIC_OPTIONS
|
||||
#endif
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible USB controller modes, for initialization via \ref USB_Init() and indication back to the
|
||||
* user application via \ref USB_CurrentMode.
|
||||
*/
|
||||
enum USB_Modes_t
|
||||
{
|
||||
USB_MODE_None = 0, /**< Indicates that the controller is currently not initialized in any specific USB mode. */
|
||||
USB_MODE_Device = 1, /**< Indicates that the controller is currently initialized in USB Device mode. */
|
||||
USB_MODE_Host = 2, /**< Indicates that the controller is currently initialized in USB Host mode. */
|
||||
USB_MODE_UID = 3, /**< Indicates that the controller should determine the USB mode from the UID pin of the
|
||||
* USB connector.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#if defined(USB_SERIES_UC3A3_AVR32) || defined(USB_SERIES_UC3A4_AVR32)
|
||||
#define USB_CLOCK_REQUIRED_FREQ 12000000UL
|
||||
#else
|
||||
#define USB_CLOCK_REQUIRED_FREQ 48000000UL
|
||||
#endif
|
||||
|
||||
/* Function Prototypes: */
|
||||
#if defined(__INCLUDE_FROM_USB_CONTROLLER_C)
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
static void USB_Init_Device(void);
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
static void USB_Init_Host(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
static inline void USB_OTGPAD_On(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_OTGPAD_On(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.otgpade = true;
|
||||
}
|
||||
|
||||
static inline void USB_OTGPAD_Off(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_OTGPAD_Off(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.otgpade = false;
|
||||
}
|
||||
|
||||
static inline void USB_CLK_Freeze(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_CLK_Freeze(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.frzclk = true;
|
||||
}
|
||||
|
||||
static inline void USB_CLK_Unfreeze(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_CLK_Unfreeze(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.frzclk = false;
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Enable(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.usbe = true;
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Disable(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.usbe = false;
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Reset(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Reset(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.usbe = false;
|
||||
AVR32_USBB.USBCON.usbe = true;
|
||||
}
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
|
||||
static inline uint8_t USB_GetUSBModeFromUID(void)
|
||||
{
|
||||
if (AVR32_USBB.USBSTA.id)
|
||||
return USB_MODE_Device;
|
||||
else
|
||||
return USB_MODE_Host;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,202 +1,202 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
void USB_INT_DisableAllInterrupts(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.vbuste = false;
|
||||
AVR32_USBB.USBCON.idte = false;
|
||||
|
||||
AVR32_USBB.uhinteclr = -1;
|
||||
AVR32_USBB.udinteclr = -1;
|
||||
}
|
||||
|
||||
void USB_INT_ClearAllInterrupts(void)
|
||||
{
|
||||
AVR32_USBB.USBSTACLR.vbustic = true;
|
||||
AVR32_USBB.USBSTACLR.idtic = true;
|
||||
|
||||
AVR32_USBB.uhintclr = -1;
|
||||
AVR32_USBB.udintclr = -1;
|
||||
}
|
||||
|
||||
ISR(USB_GEN_vect)
|
||||
{
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_SOFI);
|
||||
|
||||
EVENT_USB_Device_StartOfFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_VBUSTI);
|
||||
|
||||
if (USB_VBUS_GetStatus())
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Powered;
|
||||
EVENT_USB_Device_Connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
EVENT_USB_Device_Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
|
||||
{
|
||||
USB_INT_Disable(USB_INT_SUSPI);
|
||||
USB_INT_Enable(USB_INT_WAKEUPI);
|
||||
|
||||
USB_CLK_Freeze();
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Suspended;
|
||||
EVENT_USB_Device_Suspend();
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
|
||||
{
|
||||
USB_CLK_Unfreeze();
|
||||
|
||||
USB_INT_Clear(USB_INT_WAKEUPI);
|
||||
|
||||
USB_INT_Disable(USB_INT_WAKEUPI);
|
||||
USB_INT_Enable(USB_INT_SUSPI);
|
||||
|
||||
if (USB_Device_ConfigurationNumber)
|
||||
USB_DeviceState = DEVICE_STATE_Configured;
|
||||
else
|
||||
USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
|
||||
|
||||
EVENT_USB_Device_WakeUp();
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_EORSTI);
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Default;
|
||||
USB_Device_ConfigurationNumber = 0;
|
||||
|
||||
USB_INT_Clear(USB_INT_SUSPI);
|
||||
USB_INT_Disable(USB_INT_SUSPI);
|
||||
USB_INT_Enable(USB_INT_WAKEUPI);
|
||||
|
||||
USB_Device_SetDeviceAddress(0);
|
||||
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
|
||||
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
EVENT_USB_Device_Reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
|
||||
EVENT_USB_Host_StartOfFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_DDISCI);
|
||||
USB_INT_Clear(USB_INT_DCONNI);
|
||||
USB_INT_Disable(USB_INT_DDISCI);
|
||||
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_VBERRI);
|
||||
|
||||
USB_Host_VBUS_Manual_Off();
|
||||
USB_Host_VBUS_Auto_Off();
|
||||
|
||||
EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_HostState = HOST_STATE_Unattached;
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_DCONNI) && USB_INT_IsEnabled(USB_INT_DCONNI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_DCONNI);
|
||||
USB_INT_Disable(USB_INT_DCONNI);
|
||||
|
||||
EVENT_USB_Host_DeviceAttached();
|
||||
|
||||
USB_INT_Enable(USB_INT_DDISCI);
|
||||
|
||||
USB_HostState = HOST_STATE_Powered;
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_BCERRI);
|
||||
|
||||
EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_IDTI);
|
||||
|
||||
if (USB_DeviceState != DEVICE_STATE_Unattached)
|
||||
EVENT_USB_Device_Disconnect();
|
||||
|
||||
if (USB_HostState != HOST_STATE_Unattached)
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_CurrentMode = USB_GetUSBModeFromUID();
|
||||
USB_ResetInterface();
|
||||
|
||||
EVENT_USB_UIDChange();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
void USB_INT_DisableAllInterrupts(void)
|
||||
{
|
||||
AVR32_USBB.USBCON.vbuste = false;
|
||||
AVR32_USBB.USBCON.idte = false;
|
||||
|
||||
AVR32_USBB.uhinteclr = -1;
|
||||
AVR32_USBB.udinteclr = -1;
|
||||
}
|
||||
|
||||
void USB_INT_ClearAllInterrupts(void)
|
||||
{
|
||||
AVR32_USBB.USBSTACLR.vbustic = true;
|
||||
AVR32_USBB.USBSTACLR.idtic = true;
|
||||
|
||||
AVR32_USBB.uhintclr = -1;
|
||||
AVR32_USBB.udintclr = -1;
|
||||
}
|
||||
|
||||
ISR(USB_GEN_vect)
|
||||
{
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_SOFI);
|
||||
|
||||
EVENT_USB_Device_StartOfFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_VBUSTI);
|
||||
|
||||
if (USB_VBUS_GetStatus())
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Powered;
|
||||
EVENT_USB_Device_Connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
EVENT_USB_Device_Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
|
||||
{
|
||||
USB_INT_Disable(USB_INT_SUSPI);
|
||||
USB_INT_Enable(USB_INT_WAKEUPI);
|
||||
|
||||
USB_CLK_Freeze();
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Suspended;
|
||||
EVENT_USB_Device_Suspend();
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
|
||||
{
|
||||
USB_CLK_Unfreeze();
|
||||
|
||||
USB_INT_Clear(USB_INT_WAKEUPI);
|
||||
|
||||
USB_INT_Disable(USB_INT_WAKEUPI);
|
||||
USB_INT_Enable(USB_INT_SUSPI);
|
||||
|
||||
if (USB_Device_ConfigurationNumber)
|
||||
USB_DeviceState = DEVICE_STATE_Configured;
|
||||
else
|
||||
USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
|
||||
|
||||
EVENT_USB_Device_WakeUp();
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_EORSTI);
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Default;
|
||||
USB_Device_ConfigurationNumber = 0;
|
||||
|
||||
USB_INT_Clear(USB_INT_SUSPI);
|
||||
USB_INT_Disable(USB_INT_SUSPI);
|
||||
USB_INT_Enable(USB_INT_WAKEUPI);
|
||||
|
||||
USB_Device_SetDeviceAddress(0);
|
||||
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
|
||||
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
EVENT_USB_Device_Reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_HSOFI);
|
||||
|
||||
EVENT_USB_Host_StartOfFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_DDISCI);
|
||||
USB_INT_Clear(USB_INT_DCONNI);
|
||||
USB_INT_Disable(USB_INT_DDISCI);
|
||||
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_VBERRI);
|
||||
|
||||
USB_Host_VBUS_Manual_Off();
|
||||
USB_Host_VBUS_Auto_Off();
|
||||
|
||||
EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_HostState = HOST_STATE_Unattached;
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_DCONNI) && USB_INT_IsEnabled(USB_INT_DCONNI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_DCONNI);
|
||||
USB_INT_Disable(USB_INT_DCONNI);
|
||||
|
||||
EVENT_USB_Host_DeviceAttached();
|
||||
|
||||
USB_INT_Enable(USB_INT_DDISCI);
|
||||
|
||||
USB_HostState = HOST_STATE_Powered;
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_BCERRI);
|
||||
|
||||
EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_IDTI);
|
||||
|
||||
if (USB_DeviceState != DEVICE_STATE_Unattached)
|
||||
EVENT_USB_Device_Disconnect();
|
||||
|
||||
if (USB_HostState != HOST_STATE_Unattached)
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_CurrentMode = USB_GetUSBModeFromUID();
|
||||
USB_ResetInterface();
|
||||
|
||||
EVENT_USB_UIDChange();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,353 +1,353 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Controller Interrupt definitions for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* This file contains definitions required for the correct handling of low level USB service routine interrupts
|
||||
* from the USB controller.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
#ifndef __USBINTERRUPT_UC3_H__
|
||||
#define __USBINTERRUPT_UC3_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Enums: */
|
||||
enum USB_Interrupts_t
|
||||
{
|
||||
USB_INT_VBUSTI = 0,
|
||||
#if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
|
||||
USB_INT_IDTI = 1,
|
||||
#endif
|
||||
#if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
|
||||
USB_INT_WAKEUPI = 2,
|
||||
USB_INT_SUSPI = 3,
|
||||
USB_INT_EORSTI = 4,
|
||||
USB_INT_SOFI = 5,
|
||||
#endif
|
||||
#if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
|
||||
USB_INT_HSOFI = 6,
|
||||
USB_INT_DCONNI = 7,
|
||||
USB_INT_DDISCI = 8,
|
||||
USB_INT_RSTI = 9,
|
||||
USB_INT_BCERRI = 10,
|
||||
USB_INT_VBERRI = 11,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Enable(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
AVR32_USBB.USBCON.vbuste = true;
|
||||
break;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
AVR32_USBB.USBCON.idte = true;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
AVR32_USBB.UDINTESET.wakeupes = true;
|
||||
break;
|
||||
case USB_INT_SUSPI:
|
||||
AVR32_USBB.UDINTESET.suspes = true;
|
||||
break;
|
||||
case USB_INT_EORSTI:
|
||||
AVR32_USBB.UDINTESET.eorstes = true;
|
||||
break;
|
||||
case USB_INT_SOFI:
|
||||
AVR32_USBB.UDINTESET.sofes = true;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
AVR32_USBB.UHINTESET.hsofies = true;
|
||||
break;
|
||||
case USB_INT_DCONNI:
|
||||
AVR32_USBB.UHINTESET.dconnies = true;
|
||||
break;
|
||||
case USB_INT_DDISCI:
|
||||
AVR32_USBB.UHINTESET.ddiscies = true;
|
||||
break;
|
||||
case USB_INT_RSTI:
|
||||
AVR32_USBB.UHINTESET.rsties = true;
|
||||
break;
|
||||
case USB_INT_BCERRI:
|
||||
AVR32_USBB.USBCON.bcerre = true;
|
||||
break;
|
||||
case USB_INT_VBERRI:
|
||||
AVR32_USBB.USBCON.vberre = true;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Disable(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
AVR32_USBB.USBCON.vbuste = false;
|
||||
break;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
AVR32_USBB.USBCON.idte = false;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
AVR32_USBB.UDINTECLR.wakeupec = true;
|
||||
break;
|
||||
case USB_INT_SUSPI:
|
||||
AVR32_USBB.UDINTECLR.suspec = true;
|
||||
break;
|
||||
case USB_INT_EORSTI:
|
||||
AVR32_USBB.UDINTECLR.eorstec = true;
|
||||
break;
|
||||
case USB_INT_SOFI:
|
||||
AVR32_USBB.UDINTECLR.sofec = true;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
AVR32_USBB.UHINTECLR.hsofiec = true;
|
||||
break;
|
||||
case USB_INT_DCONNI:
|
||||
AVR32_USBB.UHINTECLR.dconniec = true;
|
||||
break;
|
||||
case USB_INT_DDISCI:
|
||||
AVR32_USBB.UHINTECLR.ddisciec = true;
|
||||
break;
|
||||
case USB_INT_RSTI:
|
||||
AVR32_USBB.UHINTECLR.rstiec = true;
|
||||
break;
|
||||
case USB_INT_BCERRI:
|
||||
AVR32_USBB.USBCON.bcerre = false;
|
||||
break;
|
||||
case USB_INT_VBERRI:
|
||||
AVR32_USBB.USBCON.vberre = false;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Clear(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
AVR32_USBB.USBSTACLR.vbustic = true;
|
||||
(void)AVR32_USBB.USBSTACLR;
|
||||
break;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
AVR32_USBB.USBSTACLR.idtic = true;
|
||||
(void)AVR32_USBB.USBSTACLR;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
AVR32_USBB.UDINTCLR.wakeupc = true;
|
||||
(void)AVR32_USBB.UDINTCLR;
|
||||
break;
|
||||
case USB_INT_SUSPI:
|
||||
AVR32_USBB.UDINTCLR.suspc = true;
|
||||
(void)AVR32_USBB.UDINTCLR;
|
||||
break;
|
||||
case USB_INT_EORSTI:
|
||||
AVR32_USBB.UDINTCLR.eorstc = true;
|
||||
(void)AVR32_USBB.UDINTCLR;
|
||||
break;
|
||||
case USB_INT_SOFI:
|
||||
AVR32_USBB.UDINTCLR.sofc = true;
|
||||
(void)AVR32_USBB.UDINTCLR;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
AVR32_USBB.UHINTCLR.hsofic = true;
|
||||
(void)AVR32_USBB.UHINTCLR;
|
||||
break;
|
||||
case USB_INT_DCONNI:
|
||||
AVR32_USBB.UHINTCLR.dconnic = true;
|
||||
(void)AVR32_USBB.UHINTCLR;
|
||||
break;
|
||||
case USB_INT_DDISCI:
|
||||
AVR32_USBB.UHINTCLR.ddiscic = true;
|
||||
(void)AVR32_USBB.UHINTCLR;
|
||||
break;
|
||||
case USB_INT_RSTI:
|
||||
AVR32_USBB.UHINTCLR.rstic = true;
|
||||
(void)AVR32_USBB.UHINTCLR;
|
||||
break;
|
||||
case USB_INT_BCERRI:
|
||||
AVR32_USBB.USBSTACLR.bcerric = true;
|
||||
(void)AVR32_USBB.USBSTACLR;
|
||||
break;
|
||||
case USB_INT_VBERRI:
|
||||
AVR32_USBB.USBSTACLR.vberric = true;
|
||||
(void)AVR32_USBB.USBSTACLR;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
return AVR32_USBB.USBCON.vbuste;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
return AVR32_USBB.USBCON.idte;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
return AVR32_USBB.UDINTE.wakeupe;
|
||||
case USB_INT_SUSPI:
|
||||
return AVR32_USBB.UDINTE.suspe;
|
||||
case USB_INT_EORSTI:
|
||||
return AVR32_USBB.UDINTE.eorste;
|
||||
case USB_INT_SOFI:
|
||||
return AVR32_USBB.UDINTE.sofe;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
return AVR32_USBB.UHINTE.hsofie;
|
||||
case USB_INT_DCONNI:
|
||||
return AVR32_USBB.UHINTE.dconnie;
|
||||
case USB_INT_DDISCI:
|
||||
return AVR32_USBB.UHINTE.ddiscie;
|
||||
case USB_INT_RSTI:
|
||||
return AVR32_USBB.UHINTE.rstie;
|
||||
case USB_INT_BCERRI:
|
||||
return AVR32_USBB.USBCON.bcerre;
|
||||
case USB_INT_VBERRI:
|
||||
return AVR32_USBB.USBCON.vberre;
|
||||
#endif
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
return AVR32_USBB.USBSTA.vbusti;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
return AVR32_USBB.USBSTA.idti;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
return AVR32_USBB.UDINT.wakeup;
|
||||
case USB_INT_SUSPI:
|
||||
return AVR32_USBB.UDINT.susp;
|
||||
case USB_INT_EORSTI:
|
||||
return AVR32_USBB.UDINT.eorst;
|
||||
case USB_INT_SOFI:
|
||||
return AVR32_USBB.UDINT.sof;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
return AVR32_USBB.UHINT.hsofi;
|
||||
case USB_INT_DCONNI:
|
||||
return AVR32_USBB.UHINT.dconni;
|
||||
case USB_INT_DDISCI:
|
||||
return AVR32_USBB.UHINT.ddisci;
|
||||
case USB_INT_RSTI:
|
||||
return AVR32_USBB.UHINT.rsti;
|
||||
case USB_INT_BCERRI:
|
||||
return AVR32_USBB.USBSTA.bcerri;
|
||||
case USB_INT_VBERRI:
|
||||
return AVR32_USBB.USBSTA.vberri;
|
||||
#endif
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Includes: */
|
||||
#include "../USBMode.h"
|
||||
#include "../Events.h"
|
||||
#include "../USBController.h"
|
||||
|
||||
/* Function Prototypes: */
|
||||
void USB_INT_ClearAllInterrupts(void);
|
||||
void USB_INT_DisableAllInterrupts(void);
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* ISR Prototypes: */
|
||||
#if defined(__DOXYGEN__)
|
||||
/** Interrupt service routine handler for the USB controller ISR group. This interrupt routine <b>must</b> be
|
||||
* linked to the entire USB controller ISR vector group inside the AVR32's interrupt controller peripheral,
|
||||
* using the user application's preferred USB controller driver.
|
||||
*/
|
||||
void USB_GEN_vect(void);
|
||||
#else
|
||||
ISR(USB_GEN_vect);
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Controller Interrupt definitions for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* This file contains definitions required for the correct handling of low level USB service routine interrupts
|
||||
* from the USB controller.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
#ifndef __USBINTERRUPT_UC3_H__
|
||||
#define __USBINTERRUPT_UC3_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Enums: */
|
||||
enum USB_Interrupts_t
|
||||
{
|
||||
USB_INT_VBUSTI = 0,
|
||||
#if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
|
||||
USB_INT_IDTI = 1,
|
||||
#endif
|
||||
#if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
|
||||
USB_INT_WAKEUPI = 2,
|
||||
USB_INT_SUSPI = 3,
|
||||
USB_INT_EORSTI = 4,
|
||||
USB_INT_SOFI = 5,
|
||||
#endif
|
||||
#if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
|
||||
USB_INT_HSOFI = 6,
|
||||
USB_INT_DCONNI = 7,
|
||||
USB_INT_DDISCI = 8,
|
||||
USB_INT_RSTI = 9,
|
||||
USB_INT_BCERRI = 10,
|
||||
USB_INT_VBERRI = 11,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Enable(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
AVR32_USBB.USBCON.vbuste = true;
|
||||
break;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
AVR32_USBB.USBCON.idte = true;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
AVR32_USBB.UDINTESET.wakeupes = true;
|
||||
break;
|
||||
case USB_INT_SUSPI:
|
||||
AVR32_USBB.UDINTESET.suspes = true;
|
||||
break;
|
||||
case USB_INT_EORSTI:
|
||||
AVR32_USBB.UDINTESET.eorstes = true;
|
||||
break;
|
||||
case USB_INT_SOFI:
|
||||
AVR32_USBB.UDINTESET.sofes = true;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
AVR32_USBB.UHINTESET.hsofies = true;
|
||||
break;
|
||||
case USB_INT_DCONNI:
|
||||
AVR32_USBB.UHINTESET.dconnies = true;
|
||||
break;
|
||||
case USB_INT_DDISCI:
|
||||
AVR32_USBB.UHINTESET.ddiscies = true;
|
||||
break;
|
||||
case USB_INT_RSTI:
|
||||
AVR32_USBB.UHINTESET.rsties = true;
|
||||
break;
|
||||
case USB_INT_BCERRI:
|
||||
AVR32_USBB.USBCON.bcerre = true;
|
||||
break;
|
||||
case USB_INT_VBERRI:
|
||||
AVR32_USBB.USBCON.vberre = true;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Disable(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
AVR32_USBB.USBCON.vbuste = false;
|
||||
break;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
AVR32_USBB.USBCON.idte = false;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
AVR32_USBB.UDINTECLR.wakeupec = true;
|
||||
break;
|
||||
case USB_INT_SUSPI:
|
||||
AVR32_USBB.UDINTECLR.suspec = true;
|
||||
break;
|
||||
case USB_INT_EORSTI:
|
||||
AVR32_USBB.UDINTECLR.eorstec = true;
|
||||
break;
|
||||
case USB_INT_SOFI:
|
||||
AVR32_USBB.UDINTECLR.sofec = true;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
AVR32_USBB.UHINTECLR.hsofiec = true;
|
||||
break;
|
||||
case USB_INT_DCONNI:
|
||||
AVR32_USBB.UHINTECLR.dconniec = true;
|
||||
break;
|
||||
case USB_INT_DDISCI:
|
||||
AVR32_USBB.UHINTECLR.ddisciec = true;
|
||||
break;
|
||||
case USB_INT_RSTI:
|
||||
AVR32_USBB.UHINTECLR.rstiec = true;
|
||||
break;
|
||||
case USB_INT_BCERRI:
|
||||
AVR32_USBB.USBCON.bcerre = false;
|
||||
break;
|
||||
case USB_INT_VBERRI:
|
||||
AVR32_USBB.USBCON.vberre = false;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Clear(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
AVR32_USBB.USBSTACLR.vbustic = true;
|
||||
(void)AVR32_USBB.USBSTACLR;
|
||||
break;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
AVR32_USBB.USBSTACLR.idtic = true;
|
||||
(void)AVR32_USBB.USBSTACLR;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
AVR32_USBB.UDINTCLR.wakeupc = true;
|
||||
(void)AVR32_USBB.UDINTCLR;
|
||||
break;
|
||||
case USB_INT_SUSPI:
|
||||
AVR32_USBB.UDINTCLR.suspc = true;
|
||||
(void)AVR32_USBB.UDINTCLR;
|
||||
break;
|
||||
case USB_INT_EORSTI:
|
||||
AVR32_USBB.UDINTCLR.eorstc = true;
|
||||
(void)AVR32_USBB.UDINTCLR;
|
||||
break;
|
||||
case USB_INT_SOFI:
|
||||
AVR32_USBB.UDINTCLR.sofc = true;
|
||||
(void)AVR32_USBB.UDINTCLR;
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
AVR32_USBB.UHINTCLR.hsofic = true;
|
||||
(void)AVR32_USBB.UHINTCLR;
|
||||
break;
|
||||
case USB_INT_DCONNI:
|
||||
AVR32_USBB.UHINTCLR.dconnic = true;
|
||||
(void)AVR32_USBB.UHINTCLR;
|
||||
break;
|
||||
case USB_INT_DDISCI:
|
||||
AVR32_USBB.UHINTCLR.ddiscic = true;
|
||||
(void)AVR32_USBB.UHINTCLR;
|
||||
break;
|
||||
case USB_INT_RSTI:
|
||||
AVR32_USBB.UHINTCLR.rstic = true;
|
||||
(void)AVR32_USBB.UHINTCLR;
|
||||
break;
|
||||
case USB_INT_BCERRI:
|
||||
AVR32_USBB.USBSTACLR.bcerric = true;
|
||||
(void)AVR32_USBB.USBSTACLR;
|
||||
break;
|
||||
case USB_INT_VBERRI:
|
||||
AVR32_USBB.USBSTACLR.vberric = true;
|
||||
(void)AVR32_USBB.USBSTACLR;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
return AVR32_USBB.USBCON.vbuste;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
return AVR32_USBB.USBCON.idte;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
return AVR32_USBB.UDINTE.wakeupe;
|
||||
case USB_INT_SUSPI:
|
||||
return AVR32_USBB.UDINTE.suspe;
|
||||
case USB_INT_EORSTI:
|
||||
return AVR32_USBB.UDINTE.eorste;
|
||||
case USB_INT_SOFI:
|
||||
return AVR32_USBB.UDINTE.sofe;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
return AVR32_USBB.UHINTE.hsofie;
|
||||
case USB_INT_DCONNI:
|
||||
return AVR32_USBB.UHINTE.dconnie;
|
||||
case USB_INT_DDISCI:
|
||||
return AVR32_USBB.UHINTE.ddiscie;
|
||||
case USB_INT_RSTI:
|
||||
return AVR32_USBB.UHINTE.rstie;
|
||||
case USB_INT_BCERRI:
|
||||
return AVR32_USBB.USBCON.bcerre;
|
||||
case USB_INT_VBERRI:
|
||||
return AVR32_USBB.USBCON.vberre;
|
||||
#endif
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_VBUSTI:
|
||||
return AVR32_USBB.USBSTA.vbusti;
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
case USB_INT_IDTI:
|
||||
return AVR32_USBB.USBSTA.idti;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
case USB_INT_WAKEUPI:
|
||||
return AVR32_USBB.UDINT.wakeup;
|
||||
case USB_INT_SUSPI:
|
||||
return AVR32_USBB.UDINT.susp;
|
||||
case USB_INT_EORSTI:
|
||||
return AVR32_USBB.UDINT.eorst;
|
||||
case USB_INT_SOFI:
|
||||
return AVR32_USBB.UDINT.sof;
|
||||
#endif
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
case USB_INT_HSOFI:
|
||||
return AVR32_USBB.UHINT.hsofi;
|
||||
case USB_INT_DCONNI:
|
||||
return AVR32_USBB.UHINT.dconni;
|
||||
case USB_INT_DDISCI:
|
||||
return AVR32_USBB.UHINT.ddisci;
|
||||
case USB_INT_RSTI:
|
||||
return AVR32_USBB.UHINT.rsti;
|
||||
case USB_INT_BCERRI:
|
||||
return AVR32_USBB.USBSTA.bcerri;
|
||||
case USB_INT_VBERRI:
|
||||
return AVR32_USBB.USBSTA.vberri;
|
||||
#endif
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Includes: */
|
||||
#include "../USBMode.h"
|
||||
#include "../Events.h"
|
||||
#include "../USBController.h"
|
||||
|
||||
/* Function Prototypes: */
|
||||
void USB_INT_ClearAllInterrupts(void);
|
||||
void USB_INT_DisableAllInterrupts(void);
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* ISR Prototypes: */
|
||||
#if defined(__DOXYGEN__)
|
||||
/** Interrupt service routine handler for the USB controller ISR group. This interrupt routine <b>must</b> be
|
||||
* linked to the entire USB controller ISR vector group inside the AVR32's interrupt controller peripheral,
|
||||
* using the user application's preferred USB controller driver.
|
||||
*/
|
||||
void USB_GEN_vect(void);
|
||||
#else
|
||||
ISR(USB_GEN_vect);
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB Controller definitions for all architectures.
|
||||
* \copydetails Group_USBManagement
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_USBManagement USB Interface Management
|
||||
* \brief USB Controller definitions for general USB controller management.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the setup and management of the USB interface.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBCONTROLLER_H__
|
||||
#define __USBCONTROLLER_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks and Defines: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/USBController_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/USBController_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/USBController_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common USB Controller definitions for all architectures.
|
||||
* \copydetails Group_USBManagement
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_USBManagement USB Interface Management
|
||||
* \brief USB Controller definitions for general USB controller management.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the setup and management of the USB interface.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBCONTROLLER_H__
|
||||
#define __USBCONTROLLER_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks and Defines: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/USBController_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/USBController_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/USBController_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB controller interrupt service routine management.
|
||||
*
|
||||
* This file contains definitions required for the correct handling of low level USB service routine interrupts
|
||||
* from the USB controller.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
#ifndef __USBINTERRUPT_H__
|
||||
#define __USBINTERRUPT_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/USBInterrupt_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/USBInterrupt_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/USBInterrupt_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB controller interrupt service routine management.
|
||||
*
|
||||
* This file contains definitions required for the correct handling of low level USB service routine interrupts
|
||||
* from the USB controller.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
#ifndef __USBINTERRUPT_H__
|
||||
#define __USBINTERRUPT_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Architecture Includes: */
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
#include "AVR8/USBInterrupt_AVR8.h"
|
||||
#elif (ARCH == ARCH_UC3)
|
||||
#include "UC3/USBInterrupt_UC3.h"
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
#include "XMEGA/USBInterrupt_XMEGA.h"
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
|
||||
#include "../Device.h"
|
||||
|
||||
void USB_Device_SendRemoteWakeup(void)
|
||||
{
|
||||
USB.CTRLB |= USB_RWAKEUP_bm;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
|
||||
#include "../Device.h"
|
||||
|
||||
void USB_Device_SendRemoteWakeup(void)
|
||||
{
|
||||
USB.CTRLB |= USB_RWAKEUP_bm;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,238 +1,238 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Device definitions for the AVR XMEGA microcontrollers.
|
||||
* \copydetails Group_Device_XMEGA
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Device
|
||||
* \defgroup Group_Device_XMEGA Device Management (XMEGA)
|
||||
* \brief USB Device definitions for the AVR XMEGA microcontrollers.
|
||||
*
|
||||
* Architecture specific USB Device definitions for the Atmel AVR XMEGA microcontrollers.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBDEVICE_XMEGA_H__
|
||||
#define __USBDEVICE_XMEGA_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../USBController.h"
|
||||
#include "../StdDescriptors.h"
|
||||
#include "../USBInterrupt.h"
|
||||
#include "../Endpoint.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
#if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
|
||||
#error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name USB Device Mode Option Masks */
|
||||
//@{
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in low speed (1.5Mb/s) mode.
|
||||
*
|
||||
* \note Low Speed mode is not available on all USB AVR models.
|
||||
* \n
|
||||
*
|
||||
* \note Restrictions apply on the number, size and type of endpoints which can be used
|
||||
* when running in low speed mode - refer to the USB 2.0 specification.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_LOWSPEED (1 << 0)
|
||||
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in full speed (12Mb/s) mode.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_FULLSPEED (0 << 0)
|
||||
//@}
|
||||
|
||||
/** String descriptor index for the device's unique serial number string descriptor within the device.
|
||||
* This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
|
||||
* number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
|
||||
* a unique serial number internally, and setting the device descriptors serial number string index to this value
|
||||
* will cause it to use the internal serial number.
|
||||
*
|
||||
* On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
|
||||
* number for the device.
|
||||
*/
|
||||
#define USE_INTERNAL_SERIAL 0xDC
|
||||
|
||||
/** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
|
||||
* model.
|
||||
*/
|
||||
#define INTERNAL_SERIAL_LENGTH_BITS (8 * (1 + (offsetof(NVM_PROD_SIGNATURES_t, COORDY1) - offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0))))
|
||||
|
||||
/** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
|
||||
* model.
|
||||
*/
|
||||
#define INTERNAL_SERIAL_START_ADDRESS offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0)
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Sends a Remote Wakeup request to the host. This signals to the host that the device should
|
||||
* be taken out of suspended mode, and communications should resume.
|
||||
*
|
||||
* Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
|
||||
* host computer when the host has suspended all USB devices to enter a low power state.
|
||||
*
|
||||
* \note This macro should only be used if the device has indicated to the host that it
|
||||
* supports the Remote Wakeup feature in the device descriptors, and should only be
|
||||
* issued if the host is currently allowing remote wakeup events from the device (i.e.,
|
||||
* the \ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP
|
||||
* compile time option is used, this macro is unavailable.
|
||||
* \n\n
|
||||
*
|
||||
* \note The USB clock must be running for this function to operate. If the stack is initialized with
|
||||
* the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
|
||||
* before attempting to call this function.
|
||||
*
|
||||
* \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
|
||||
*/
|
||||
void USB_Device_SendRemoteWakeup(void);
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
|
||||
* the frame number is incremented by one.
|
||||
*/
|
||||
static inline uint16_t USB_Device_GetFrameNumber(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint16_t USB_Device_GetFrameNumber(void)
|
||||
{
|
||||
return (((uint16_t)USB_EndpointTable.FRAMENUMH << 8) | USB_EndpointTable.FRAMENUML);
|
||||
}
|
||||
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
/** Enables the device mode Start Of Frame events. When enabled, this causes the
|
||||
* \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
|
||||
* at the start of each USB frame when enumerated in device mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_EnableSOFEvents(void)
|
||||
{
|
||||
USB.INTCTRLA |= USB_SOFIE_bm;
|
||||
}
|
||||
|
||||
/** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
|
||||
* \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_DisableSOFEvents(void)
|
||||
{
|
||||
USB.INTCTRLA &= ~USB_SOFIE_bm;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Inline Functions: */
|
||||
static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetLowSpeed(void)
|
||||
{
|
||||
USB.CTRLA &= ~USB_SPEED_bm;
|
||||
}
|
||||
|
||||
static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetFullSpeed(void)
|
||||
{
|
||||
USB.CTRLA |= USB_SPEED_bm;
|
||||
}
|
||||
|
||||
static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
|
||||
{
|
||||
USB.ADDR = Address;
|
||||
}
|
||||
|
||||
static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_Device_IsAddressSet(void)
|
||||
{
|
||||
return ((USB.ADDR != 0) ? true : false);
|
||||
}
|
||||
|
||||
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)
|
||||
{
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS;
|
||||
|
||||
for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)
|
||||
{
|
||||
uint8_t SerialByte;
|
||||
|
||||
NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
|
||||
SerialByte = pgm_read_byte(SigReadAddress);
|
||||
|
||||
if (SerialCharNum & 0x01)
|
||||
{
|
||||
SerialByte >>= 4;
|
||||
SigReadAddress++;
|
||||
}
|
||||
|
||||
SerialByte &= 0x0F;
|
||||
|
||||
UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
|
||||
(('A' - 10) + SerialByte) : ('0' + SerialByte));
|
||||
}
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Device definitions for the AVR XMEGA microcontrollers.
|
||||
* \copydetails Group_Device_XMEGA
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Device
|
||||
* \defgroup Group_Device_XMEGA Device Management (XMEGA)
|
||||
* \brief USB Device definitions for the AVR XMEGA microcontrollers.
|
||||
*
|
||||
* Architecture specific USB Device definitions for the Atmel AVR XMEGA microcontrollers.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBDEVICE_XMEGA_H__
|
||||
#define __USBDEVICE_XMEGA_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../USBController.h"
|
||||
#include "../StdDescriptors.h"
|
||||
#include "../USBInterrupt.h"
|
||||
#include "../Endpoint.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
#if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
|
||||
#error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name USB Device Mode Option Masks */
|
||||
//@{
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in low speed (1.5Mb/s) mode.
|
||||
*
|
||||
* \note Low Speed mode is not available on all USB AVR models.
|
||||
* \n
|
||||
*
|
||||
* \note Restrictions apply on the number, size and type of endpoints which can be used
|
||||
* when running in low speed mode - refer to the USB 2.0 specification.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_LOWSPEED (1 << 0)
|
||||
|
||||
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
|
||||
* USB interface should be initialized in full speed (12Mb/s) mode.
|
||||
*/
|
||||
#define USB_DEVICE_OPT_FULLSPEED (0 << 0)
|
||||
//@}
|
||||
|
||||
/** String descriptor index for the device's unique serial number string descriptor within the device.
|
||||
* This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
|
||||
* number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
|
||||
* a unique serial number internally, and setting the device descriptors serial number string index to this value
|
||||
* will cause it to use the internal serial number.
|
||||
*
|
||||
* On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
|
||||
* number for the device.
|
||||
*/
|
||||
#define USE_INTERNAL_SERIAL 0xDC
|
||||
|
||||
/** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
|
||||
* model.
|
||||
*/
|
||||
#define INTERNAL_SERIAL_LENGTH_BITS (8 * (1 + (offsetof(NVM_PROD_SIGNATURES_t, COORDY1) - offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0))))
|
||||
|
||||
/** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
|
||||
* model.
|
||||
*/
|
||||
#define INTERNAL_SERIAL_START_ADDRESS offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0)
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Sends a Remote Wakeup request to the host. This signals to the host that the device should
|
||||
* be taken out of suspended mode, and communications should resume.
|
||||
*
|
||||
* Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
|
||||
* host computer when the host has suspended all USB devices to enter a low power state.
|
||||
*
|
||||
* \note This macro should only be used if the device has indicated to the host that it
|
||||
* supports the Remote Wakeup feature in the device descriptors, and should only be
|
||||
* issued if the host is currently allowing remote wakeup events from the device (i.e.,
|
||||
* the \ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP
|
||||
* compile time option is used, this macro is unavailable.
|
||||
* \n\n
|
||||
*
|
||||
* \note The USB clock must be running for this function to operate. If the stack is initialized with
|
||||
* the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
|
||||
* before attempting to call this function.
|
||||
*
|
||||
* \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
|
||||
*/
|
||||
void USB_Device_SendRemoteWakeup(void);
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
|
||||
* the frame number is incremented by one.
|
||||
*/
|
||||
static inline uint16_t USB_Device_GetFrameNumber(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint16_t USB_Device_GetFrameNumber(void)
|
||||
{
|
||||
return (((uint16_t)USB_EndpointTable.FRAMENUMH << 8) | USB_EndpointTable.FRAMENUML);
|
||||
}
|
||||
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
/** Enables the device mode Start Of Frame events. When enabled, this causes the
|
||||
* \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
|
||||
* at the start of each USB frame when enumerated in device mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_EnableSOFEvents(void)
|
||||
{
|
||||
USB.INTCTRLA |= USB_SOFIE_bm;
|
||||
}
|
||||
|
||||
/** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
|
||||
* \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
|
||||
*
|
||||
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
|
||||
*/
|
||||
static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_DisableSOFEvents(void)
|
||||
{
|
||||
USB.INTCTRLA &= ~USB_SOFIE_bm;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Inline Functions: */
|
||||
static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetLowSpeed(void)
|
||||
{
|
||||
USB.CTRLA &= ~USB_SPEED_bm;
|
||||
}
|
||||
|
||||
static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetFullSpeed(void)
|
||||
{
|
||||
USB.CTRLA |= USB_SPEED_bm;
|
||||
}
|
||||
|
||||
static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
|
||||
{
|
||||
USB.ADDR = Address;
|
||||
}
|
||||
|
||||
static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_Device_IsAddressSet(void)
|
||||
{
|
||||
return ((USB.ADDR != 0) ? true : false);
|
||||
}
|
||||
|
||||
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString) ATTR_NON_NULL_PTR_ARG(1);
|
||||
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)
|
||||
{
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS;
|
||||
|
||||
for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)
|
||||
{
|
||||
uint8_t SerialByte;
|
||||
|
||||
NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
|
||||
SerialByte = pgm_read_byte(SigReadAddress);
|
||||
|
||||
if (SerialCharNum & 0x01)
|
||||
{
|
||||
SerialByte >>= 4;
|
||||
SigReadAddress++;
|
||||
}
|
||||
|
||||
SerialByte &= 0x0F;
|
||||
|
||||
UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
|
||||
(('A' - 10) + SerialByte) : ('0' + SerialByte));
|
||||
}
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
|
||||
#include "../Endpoint.h"
|
||||
|
||||
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
|
||||
uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
|
||||
#endif
|
||||
|
||||
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
|
||||
const uint8_t UECFG0XData,
|
||||
const uint8_t UECFG1XData)
|
||||
{
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
void Endpoint_ClearEndpoints(void)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Endpoint_ClearStatusStage(void)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
#if !defined(CONTROL_ONLY_DEVICE)
|
||||
uint8_t Endpoint_WaitUntilReady(void)
|
||||
{
|
||||
return 0; // TODO
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
|
||||
#include "../Endpoint.h"
|
||||
|
||||
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
|
||||
uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
|
||||
#endif
|
||||
|
||||
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
|
||||
const uint8_t UECFG0XData,
|
||||
const uint8_t UECFG1XData)
|
||||
{
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
void Endpoint_ClearEndpoints(void)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Endpoint_ClearStatusStage(void)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
#if !defined(CONTROL_ONLY_DEVICE)
|
||||
uint8_t Endpoint_WaitUntilReady(void)
|
||||
{
|
||||
return 0; // TODO
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#if defined(TEMPLATE_FUNC_NAME)
|
||||
|
||||
uint8_t TEMPLATE_FUNC_NAME (void* const Buffer,
|
||||
uint16_t Length)
|
||||
{
|
||||
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
|
||||
|
||||
if (!(Length))
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
while (Length)
|
||||
{
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_RWCSTREAM_BusSuspended;
|
||||
else if (Endpoint_IsSETUPReceived())
|
||||
return ENDPOINT_RWCSTREAM_HostAborted;
|
||||
|
||||
if (Endpoint_IsOUTReceived())
|
||||
{
|
||||
while (Length && Endpoint_BytesInEndpoint())
|
||||
{
|
||||
TEMPLATE_TRANSFER_BYTE(DataStream);
|
||||
TEMPLATE_BUFFER_MOVE(DataStream, 1);
|
||||
Length--;
|
||||
}
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
}
|
||||
|
||||
while (!(Endpoint_IsINReady()))
|
||||
{
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_RWCSTREAM_BusSuspended;
|
||||
}
|
||||
|
||||
return ENDPOINT_RWCSTREAM_NoError;
|
||||
}
|
||||
|
||||
#undef TEMPLATE_BUFFER_OFFSET
|
||||
#undef TEMPLATE_BUFFER_MOVE
|
||||
#undef TEMPLATE_FUNC_NAME
|
||||
#undef TEMPLATE_TRANSFER_BYTE
|
||||
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#if defined(TEMPLATE_FUNC_NAME)
|
||||
|
||||
uint8_t TEMPLATE_FUNC_NAME (void* const Buffer,
|
||||
uint16_t Length)
|
||||
{
|
||||
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
|
||||
|
||||
if (!(Length))
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
while (Length)
|
||||
{
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_RWCSTREAM_BusSuspended;
|
||||
else if (Endpoint_IsSETUPReceived())
|
||||
return ENDPOINT_RWCSTREAM_HostAborted;
|
||||
|
||||
if (Endpoint_IsOUTReceived())
|
||||
{
|
||||
while (Length && Endpoint_BytesInEndpoint())
|
||||
{
|
||||
TEMPLATE_TRANSFER_BYTE(DataStream);
|
||||
TEMPLATE_BUFFER_MOVE(DataStream, 1);
|
||||
Length--;
|
||||
}
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
}
|
||||
|
||||
while (!(Endpoint_IsINReady()))
|
||||
{
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_RWCSTREAM_BusSuspended;
|
||||
}
|
||||
|
||||
return ENDPOINT_RWCSTREAM_NoError;
|
||||
}
|
||||
|
||||
#undef TEMPLATE_BUFFER_OFFSET
|
||||
#undef TEMPLATE_BUFFER_MOVE
|
||||
#undef TEMPLATE_FUNC_NAME
|
||||
#undef TEMPLATE_TRANSFER_BYTE
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#if defined(TEMPLATE_FUNC_NAME)
|
||||
|
||||
uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer,
|
||||
uint16_t Length)
|
||||
{
|
||||
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
|
||||
bool LastPacketFull = false;
|
||||
|
||||
if (Length > USB_ControlRequest.wLength)
|
||||
Length = USB_ControlRequest.wLength;
|
||||
else if (!(Length))
|
||||
Endpoint_ClearIN();
|
||||
|
||||
while (Length || LastPacketFull)
|
||||
{
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_RWCSTREAM_BusSuspended;
|
||||
else if (Endpoint_IsSETUPReceived())
|
||||
return ENDPOINT_RWCSTREAM_HostAborted;
|
||||
else if (Endpoint_IsOUTReceived())
|
||||
break;
|
||||
|
||||
if (Endpoint_IsINReady())
|
||||
{
|
||||
uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint();
|
||||
|
||||
while (Length && (BytesInEndpoint < USB_Device_ControlEndpointSize))
|
||||
{
|
||||
TEMPLATE_TRANSFER_BYTE(DataStream);
|
||||
TEMPLATE_BUFFER_MOVE(DataStream, 1);
|
||||
Length--;
|
||||
BytesInEndpoint++;
|
||||
}
|
||||
|
||||
LastPacketFull = (BytesInEndpoint == USB_Device_ControlEndpointSize);
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
}
|
||||
|
||||
while (!(Endpoint_IsOUTReceived()))
|
||||
{
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_RWCSTREAM_BusSuspended;
|
||||
}
|
||||
|
||||
return ENDPOINT_RWCSTREAM_NoError;
|
||||
}
|
||||
|
||||
#undef TEMPLATE_BUFFER_OFFSET
|
||||
#undef TEMPLATE_BUFFER_MOVE
|
||||
#undef TEMPLATE_FUNC_NAME
|
||||
#undef TEMPLATE_TRANSFER_BYTE
|
||||
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#if defined(TEMPLATE_FUNC_NAME)
|
||||
|
||||
uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer,
|
||||
uint16_t Length)
|
||||
{
|
||||
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
|
||||
bool LastPacketFull = false;
|
||||
|
||||
if (Length > USB_ControlRequest.wLength)
|
||||
Length = USB_ControlRequest.wLength;
|
||||
else if (!(Length))
|
||||
Endpoint_ClearIN();
|
||||
|
||||
while (Length || LastPacketFull)
|
||||
{
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_RWCSTREAM_BusSuspended;
|
||||
else if (Endpoint_IsSETUPReceived())
|
||||
return ENDPOINT_RWCSTREAM_HostAborted;
|
||||
else if (Endpoint_IsOUTReceived())
|
||||
break;
|
||||
|
||||
if (Endpoint_IsINReady())
|
||||
{
|
||||
uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint();
|
||||
|
||||
while (Length && (BytesInEndpoint < USB_Device_ControlEndpointSize))
|
||||
{
|
||||
TEMPLATE_TRANSFER_BYTE(DataStream);
|
||||
TEMPLATE_BUFFER_MOVE(DataStream, 1);
|
||||
Length--;
|
||||
BytesInEndpoint++;
|
||||
}
|
||||
|
||||
LastPacketFull = (BytesInEndpoint == USB_Device_ControlEndpointSize);
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
}
|
||||
|
||||
while (!(Endpoint_IsOUTReceived()))
|
||||
{
|
||||
uint8_t USB_DeviceState_LCL = USB_DeviceState;
|
||||
|
||||
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
|
||||
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
|
||||
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
|
||||
return ENDPOINT_RWCSTREAM_BusSuspended;
|
||||
}
|
||||
|
||||
return ENDPOINT_RWCSTREAM_NoError;
|
||||
}
|
||||
|
||||
#undef TEMPLATE_BUFFER_OFFSET
|
||||
#undef TEMPLATE_BUFFER_MOVE
|
||||
#undef TEMPLATE_FUNC_NAME
|
||||
#undef TEMPLATE_TRANSFER_BYTE
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#if defined(TEMPLATE_FUNC_NAME)
|
||||
|
||||
uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer,
|
||||
uint16_t Length,
|
||||
uint16_t* const BytesProcessed)
|
||||
{
|
||||
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
|
||||
uint16_t BytesInTransfer = 0;
|
||||
uint8_t ErrorCode;
|
||||
|
||||
if ((ErrorCode = Endpoint_WaitUntilReady()))
|
||||
return ErrorCode;
|
||||
|
||||
if (BytesProcessed != NULL)
|
||||
{
|
||||
Length -= *BytesProcessed;
|
||||
TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed);
|
||||
}
|
||||
|
||||
while (Length)
|
||||
{
|
||||
if (!(Endpoint_IsReadWriteAllowed()))
|
||||
{
|
||||
TEMPLATE_CLEAR_ENDPOINT();
|
||||
|
||||
if (BytesProcessed != NULL)
|
||||
{
|
||||
*BytesProcessed += BytesInTransfer;
|
||||
return ENDPOINT_RWSTREAM_IncompleteTransfer;
|
||||
}
|
||||
|
||||
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||
USB_USBTask();
|
||||
#endif
|
||||
|
||||
if ((ErrorCode = Endpoint_WaitUntilReady()))
|
||||
return ErrorCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
TEMPLATE_TRANSFER_BYTE(DataStream);
|
||||
TEMPLATE_BUFFER_MOVE(DataStream, 1);
|
||||
Length--;
|
||||
BytesInTransfer++;
|
||||
}
|
||||
}
|
||||
|
||||
return ENDPOINT_RWSTREAM_NoError;
|
||||
}
|
||||
|
||||
#undef TEMPLATE_FUNC_NAME
|
||||
#undef TEMPLATE_BUFFER_TYPE
|
||||
#undef TEMPLATE_TRANSFER_BYTE
|
||||
#undef TEMPLATE_CLEAR_ENDPOINT
|
||||
#undef TEMPLATE_BUFFER_OFFSET
|
||||
#undef TEMPLATE_BUFFER_MOVE
|
||||
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#if defined(TEMPLATE_FUNC_NAME)
|
||||
|
||||
uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer,
|
||||
uint16_t Length,
|
||||
uint16_t* const BytesProcessed)
|
||||
{
|
||||
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
|
||||
uint16_t BytesInTransfer = 0;
|
||||
uint8_t ErrorCode;
|
||||
|
||||
if ((ErrorCode = Endpoint_WaitUntilReady()))
|
||||
return ErrorCode;
|
||||
|
||||
if (BytesProcessed != NULL)
|
||||
{
|
||||
Length -= *BytesProcessed;
|
||||
TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed);
|
||||
}
|
||||
|
||||
while (Length)
|
||||
{
|
||||
if (!(Endpoint_IsReadWriteAllowed()))
|
||||
{
|
||||
TEMPLATE_CLEAR_ENDPOINT();
|
||||
|
||||
if (BytesProcessed != NULL)
|
||||
{
|
||||
*BytesProcessed += BytesInTransfer;
|
||||
return ENDPOINT_RWSTREAM_IncompleteTransfer;
|
||||
}
|
||||
|
||||
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||
USB_USBTask();
|
||||
#endif
|
||||
|
||||
if ((ErrorCode = Endpoint_WaitUntilReady()))
|
||||
return ErrorCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
TEMPLATE_TRANSFER_BYTE(DataStream);
|
||||
TEMPLATE_BUFFER_MOVE(DataStream, 1);
|
||||
Length--;
|
||||
BytesInTransfer++;
|
||||
}
|
||||
}
|
||||
|
||||
return ENDPOINT_RWSTREAM_NoError;
|
||||
}
|
||||
|
||||
#undef TEMPLATE_FUNC_NAME
|
||||
#undef TEMPLATE_BUFFER_TYPE
|
||||
#undef TEMPLATE_TRANSFER_BYTE
|
||||
#undef TEMPLATE_CLEAR_ENDPOINT
|
||||
#undef TEMPLATE_BUFFER_OFFSET
|
||||
#undef TEMPLATE_BUFFER_MOVE
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,169 +1,169 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#define __INCLUDE_FROM_USB_CONTROLLER_C
|
||||
#include "../USBController.h"
|
||||
|
||||
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY))
|
||||
volatile uint8_t USB_CurrentMode = USB_MODE_None;
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
volatile uint8_t USB_Options;
|
||||
#endif
|
||||
|
||||
USB_EP_TABLE_t USB_EndpointTable ATTR_ALIGNED(2);
|
||||
|
||||
void USB_Init(
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
const uint8_t Mode
|
||||
#endif
|
||||
|
||||
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS))
|
||||
,
|
||||
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
|
||||
void
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
const uint8_t Options
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
USB_Options = Options;
|
||||
#endif
|
||||
|
||||
USB_IsInitialized = true;
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
|
||||
USB.CAL0 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL0));
|
||||
NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
|
||||
USB.CAL1 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL1));
|
||||
|
||||
if ((USB_Options & USB_OPT_BUSEVENT_PRIHIGH) == USB_OPT_BUSEVENT_PRIHIGH)
|
||||
USB.INTCTRLA = (3 << USB_INTLVL_gp);
|
||||
else if ((USB_Options & USB_OPT_BUSEVENT_PRIMED) == USB_OPT_BUSEVENT_PRIMED)
|
||||
USB.INTCTRLA = (2 << USB_INTLVL_gp);
|
||||
else
|
||||
USB.INTCTRLA = (1 << USB_INTLVL_gp);
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
|
||||
void USB_Disable(void)
|
||||
{
|
||||
USB_INT_DisableAllInterrupts();
|
||||
USB_INT_ClearAllInterrupts();
|
||||
|
||||
USB_Detach();
|
||||
USB_Controller_Disable();
|
||||
|
||||
USB_IsInitialized = false;
|
||||
}
|
||||
|
||||
void USB_ResetInterface(void)
|
||||
{
|
||||
if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
|
||||
CLK.USBCTRL = ((((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp) | CLK_USBSRC_PLL_gc | CLK_USBSEN_bm);
|
||||
else
|
||||
CLK.USBCTRL = ((((F_USB / 48000000) - 1) << CLK_USBPSDIV_gp) | CLK_USBSRC_PLL_gc | CLK_USBSEN_bm);
|
||||
|
||||
USB_INT_DisableAllInterrupts();
|
||||
USB_INT_ClearAllInterrupts();
|
||||
|
||||
USB_Controller_Reset();
|
||||
USB_Init_Device();
|
||||
}
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
static void USB_Init_Device(void)
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
USB_Device_ConfigurationNumber = 0;
|
||||
|
||||
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
|
||||
USB_Device_RemoteWakeupEnabled = false;
|
||||
#endif
|
||||
|
||||
#if !defined(NO_DEVICE_SELF_POWER)
|
||||
USB_Device_CurrentlySelfPowered = false;
|
||||
#endif
|
||||
|
||||
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
|
||||
USB_Descriptor_Device_t* DeviceDescriptorPtr;
|
||||
|
||||
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \
|
||||
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
|
||||
uint8_t DescriptorAddressSpace;
|
||||
|
||||
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr, &DescriptorAddressSpace) != NO_DESCRIPTOR)
|
||||
{
|
||||
if (DescriptorAddressSpace == MEMSPACE_FLASH)
|
||||
USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
else if (DescriptorAddressSpace == MEMSPACE_EEPROM)
|
||||
USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
else
|
||||
USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
|
||||
}
|
||||
#else
|
||||
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)
|
||||
{
|
||||
#if defined(USE_RAM_DESCRIPTORS)
|
||||
USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
|
||||
#elif defined(USE_EEPROM_DESCRIPTORS)
|
||||
USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
#else
|
||||
USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
|
||||
USB_Device_SetLowSpeed();
|
||||
else
|
||||
USB_Device_SetFullSpeed();
|
||||
|
||||
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
|
||||
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
USB_INT_Enable(USB_INT_BUSEVENTI);
|
||||
|
||||
USB_Attach();
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#define __INCLUDE_FROM_USB_CONTROLLER_C
|
||||
#include "../USBController.h"
|
||||
|
||||
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY))
|
||||
volatile uint8_t USB_CurrentMode = USB_MODE_None;
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
volatile uint8_t USB_Options;
|
||||
#endif
|
||||
|
||||
USB_EP_TABLE_t USB_EndpointTable ATTR_ALIGNED(2);
|
||||
|
||||
void USB_Init(
|
||||
#if defined(USB_CAN_BE_BOTH)
|
||||
const uint8_t Mode
|
||||
#endif
|
||||
|
||||
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS))
|
||||
,
|
||||
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
|
||||
void
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
const uint8_t Options
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if !defined(USE_STATIC_OPTIONS)
|
||||
USB_Options = Options;
|
||||
#endif
|
||||
|
||||
USB_IsInitialized = true;
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
|
||||
USB.CAL0 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL0));
|
||||
NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
|
||||
USB.CAL1 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL1));
|
||||
|
||||
if ((USB_Options & USB_OPT_BUSEVENT_PRIHIGH) == USB_OPT_BUSEVENT_PRIHIGH)
|
||||
USB.INTCTRLA = (3 << USB_INTLVL_gp);
|
||||
else if ((USB_Options & USB_OPT_BUSEVENT_PRIMED) == USB_OPT_BUSEVENT_PRIMED)
|
||||
USB.INTCTRLA = (2 << USB_INTLVL_gp);
|
||||
else
|
||||
USB.INTCTRLA = (1 << USB_INTLVL_gp);
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
|
||||
void USB_Disable(void)
|
||||
{
|
||||
USB_INT_DisableAllInterrupts();
|
||||
USB_INT_ClearAllInterrupts();
|
||||
|
||||
USB_Detach();
|
||||
USB_Controller_Disable();
|
||||
|
||||
USB_IsInitialized = false;
|
||||
}
|
||||
|
||||
void USB_ResetInterface(void)
|
||||
{
|
||||
if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
|
||||
CLK.USBCTRL = ((((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp) | CLK_USBSRC_PLL_gc | CLK_USBSEN_bm);
|
||||
else
|
||||
CLK.USBCTRL = ((((F_USB / 48000000) - 1) << CLK_USBPSDIV_gp) | CLK_USBSRC_PLL_gc | CLK_USBSEN_bm);
|
||||
|
||||
USB_INT_DisableAllInterrupts();
|
||||
USB_INT_ClearAllInterrupts();
|
||||
|
||||
USB_Controller_Reset();
|
||||
USB_Init_Device();
|
||||
}
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
static void USB_Init_Device(void)
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
USB_Device_ConfigurationNumber = 0;
|
||||
|
||||
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
|
||||
USB_Device_RemoteWakeupEnabled = false;
|
||||
#endif
|
||||
|
||||
#if !defined(NO_DEVICE_SELF_POWER)
|
||||
USB_Device_CurrentlySelfPowered = false;
|
||||
#endif
|
||||
|
||||
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
|
||||
USB_Descriptor_Device_t* DeviceDescriptorPtr;
|
||||
|
||||
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \
|
||||
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
|
||||
uint8_t DescriptorAddressSpace;
|
||||
|
||||
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr, &DescriptorAddressSpace) != NO_DESCRIPTOR)
|
||||
{
|
||||
if (DescriptorAddressSpace == MEMSPACE_FLASH)
|
||||
USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
else if (DescriptorAddressSpace == MEMSPACE_EEPROM)
|
||||
USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
else
|
||||
USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
|
||||
}
|
||||
#else
|
||||
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)
|
||||
{
|
||||
#if defined(USE_RAM_DESCRIPTORS)
|
||||
USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
|
||||
#elif defined(USE_EEPROM_DESCRIPTORS)
|
||||
USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
#else
|
||||
USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
|
||||
USB_Device_SetLowSpeed();
|
||||
else
|
||||
USB_Device_SetFullSpeed();
|
||||
|
||||
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
|
||||
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
USB_INT_Enable(USB_INT_BUSEVENTI);
|
||||
|
||||
USB_Attach();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,319 +1,319 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Controller definitions for the AVR XMEGA microcontrollers.
|
||||
* \copydetails Group_USBManagement_XMEGA
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USBManagement
|
||||
* \defgroup Group_USBManagement_XMEGA USB Interface Management (XMEGA)
|
||||
* \brief USB Controller definitions for the AVR XMEGA microcontrollers.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the setup and management of the USB interface.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBCONTROLLER_XMEGA_H__
|
||||
#define __USBCONTROLLER_XMEGA_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../USBMode.h"
|
||||
#include "../Events.h"
|
||||
#include "../USBTask.h"
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* External Variables: */
|
||||
extern USB_EP_TABLE_t USB_EndpointTable;
|
||||
#endif
|
||||
|
||||
/* Includes: */
|
||||
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
|
||||
#include "../Device.h"
|
||||
#include "../Endpoint.h"
|
||||
#include "../DeviceStandardReq.h"
|
||||
#include "../EndpointStream.h"
|
||||
#endif
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks and Defines: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
#if !defined(F_USB)
|
||||
#error F_USB is not defined. You must define F_USB to the frequency of the unprescaled USB controller clock in your project makefile.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name USB Controller Option Masks */
|
||||
//@{
|
||||
/** Sets the USB bus interrupt priority level to be low priority. The USB bus interrupt is used for Start of Frame events, bus suspend
|
||||
* and resume events, bus reset events and other events related to the management of the USB bus.
|
||||
*/
|
||||
#define USB_OPT_BUSEVENT_PRILOW ((0 << 1) | (0 << 1))
|
||||
|
||||
/** Sets the USB bus interrupt priority level to be medium priority. The USB bus interrupt is used for Start of Frame events, bus suspend
|
||||
* and resume events, bus reset events and other events related to the management of the USB bus.
|
||||
*/
|
||||
#define USB_OPT_BUSEVENT_PRIMED ((0 << 1) | (1 << 1))
|
||||
|
||||
/** Sets the USB bus interrupt priority level to be high priority. The USB bus interrupt is used for Start of Frame events, bus suspend
|
||||
* and resume events, bus reset events and other events related to the management of the USB bus.
|
||||
*/
|
||||
#define USB_OPT_BUSEVENT_PRIHIGH ((1 << 1) | (0 << 1))
|
||||
//@}
|
||||
|
||||
/** \name Endpoint/Pipe Type Masks */
|
||||
//@{
|
||||
/** Mask for a CONTROL type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_CONTROL 0x00
|
||||
|
||||
/** Mask for an ISOCHRONOUS type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_ISOCHRONOUS 0x01
|
||||
|
||||
/** Mask for a BULK type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_BULK 0x02
|
||||
|
||||
/** Mask for an INTERRUPT type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_INTERRUPT 0x03
|
||||
//@}
|
||||
|
||||
#if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)
|
||||
/** Constant for the maximum software timeout period of the USB data stream transfer functions
|
||||
* (both control and standard) when in either device or host mode. If the next packet of a stream
|
||||
* is not received or acknowledged within this time period, the stream function will fail.
|
||||
*
|
||||
* This value may be overridden in the user project makefile as the value of the
|
||||
* \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch.
|
||||
*/
|
||||
#define USB_STREAM_TIMEOUT_MS 100
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Detaches the device from the USB bus. This has the effect of removing the device from any
|
||||
* attached host, ceasing USB communications. If no host is present, this prevents any host from
|
||||
* enumerating the device once attached until \ref USB_Attach() is called.
|
||||
*/
|
||||
static inline void USB_Detach(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Detach(void)
|
||||
{
|
||||
USB.CTRLB &= ~USB_ATTACH_bm;
|
||||
}
|
||||
|
||||
/** Attaches the device to the USB bus. This announces the device's presence to any attached
|
||||
* USB host, starting the enumeration process. If no host is present, attaching the device
|
||||
* will allow for enumeration once a host is connected to the device.
|
||||
*
|
||||
* This is inexplicably also required for proper operation while in host mode, to enable the
|
||||
* attachment of a device to the host. This is despite the bit being located in the device-mode
|
||||
* register and despite the datasheet making no mention of its requirement in host mode.
|
||||
*/
|
||||
static inline void USB_Attach(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Attach(void)
|
||||
{
|
||||
USB.CTRLB |= USB_ATTACH_bm;
|
||||
}
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Main function to initialize and start the USB interface. Once active, the USB interface will
|
||||
* allow for device connection to a host when in device mode, or for device enumeration while in
|
||||
* host mode.
|
||||
*
|
||||
* As the USB library relies on interrupts for the device and host mode enumeration processes,
|
||||
* the user must enable global interrupts before or shortly after this function is called. In
|
||||
* device mode, interrupts must be enabled within 500ms of this function being called to ensure
|
||||
* that the host does not time out whilst enumerating the device. In host mode, interrupts may be
|
||||
* enabled at the application's leisure however enumeration will not begin of an attached device
|
||||
* until after this has occurred.
|
||||
*
|
||||
* Calling this function when the USB interface is already initialized will cause a complete USB
|
||||
* interface reset and re-enumeration.
|
||||
*
|
||||
* \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to, a value
|
||||
* from the \ref USB_Modes_t enum.
|
||||
*
|
||||
* \param[in] Options Mask indicating the options which should be used when initializing the USB
|
||||
* interface to control the USB interface's behaviour. This should be comprised of
|
||||
* a \c USB_OPT_REG_* mask to control the regulator, a \c USB_OPT_*_PLL mask to control the
|
||||
* PLL, and a \c USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device
|
||||
* mode speed.
|
||||
*
|
||||
* \note To reduce the FLASH requirements of the library if only device or host mode is required,
|
||||
* the mode can be statically set in the project makefile by defining the token \c USB_DEVICE_ONLY
|
||||
* (for device mode) or \c USB_HOST_ONLY (for host mode), passing the token to the compiler
|
||||
* via the -D switch. If the mode is statically set, this parameter does not exist in the
|
||||
* function prototype.
|
||||
* \n\n
|
||||
*
|
||||
* \note To reduce the FLASH requirements of the library if only fixed settings are are required,
|
||||
* the options may be set statically in the same manner as the mode (see the Mode parameter of
|
||||
* this function). To statically set the USB options, pass in the \c USE_STATIC_OPTIONS token,
|
||||
* defined to the appropriate options masks. When the options are statically set, this
|
||||
* parameter does not exist in the function prototype.
|
||||
* \n\n
|
||||
*
|
||||
* \note The mode parameter does not exist on devices where only one mode is possible, such as USB
|
||||
* AVR models which only implement the USB device mode in hardware.
|
||||
*
|
||||
* \see \ref Group_Device for the \c USB_DEVICE_OPT_* masks.
|
||||
*/
|
||||
void USB_Init(
|
||||
#if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
|
||||
const uint8_t Mode
|
||||
#endif
|
||||
|
||||
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__)
|
||||
,
|
||||
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
|
||||
void
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
|
||||
const uint8_t Options
|
||||
#endif
|
||||
);
|
||||
|
||||
/** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO
|
||||
* memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface
|
||||
* is restarted with the \ref USB_Init() function.
|
||||
*/
|
||||
void USB_Disable(void);
|
||||
|
||||
/** Resets the interface, when already initialized. This will re-enumerate the device if already connected
|
||||
* to a host, or re-enumerate an already attached device when in host mode.
|
||||
*/
|
||||
void USB_ResetInterface(void);
|
||||
|
||||
/* Global Variables: */
|
||||
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__)
|
||||
/** Indicates the mode that the USB interface is currently initialized to, a value from the
|
||||
* \ref USB_Modes_t enum.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
* \n\n
|
||||
*
|
||||
* \note When the controller is initialized into UID auto-detection mode, this variable will hold the
|
||||
* currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller
|
||||
* is fixed into a specific mode (either through the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY compile time
|
||||
* options, or a limitation of the USB controller in the chosen device model) this will evaluate to
|
||||
* a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the
|
||||
* USB interface is not initialized.
|
||||
*/
|
||||
extern volatile uint8_t USB_CurrentMode;
|
||||
#elif defined(USB_DEVICE_ONLY)
|
||||
#define USB_CurrentMode USB_MODE_Device
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
|
||||
/** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init()
|
||||
* was called. This value will be one of the \c USB_MODE_* masks defined elsewhere in this module.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
*/
|
||||
extern volatile uint8_t USB_Options;
|
||||
#elif defined(USE_STATIC_OPTIONS)
|
||||
#define USB_Options USE_STATIC_OPTIONS
|
||||
#endif
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible USB controller modes, for initialization via \ref USB_Init() and indication back to the
|
||||
* user application via \ref USB_CurrentMode.
|
||||
*/
|
||||
enum USB_Modes_t
|
||||
{
|
||||
USB_MODE_None = 0, /**< Indicates that the controller is currently not initialized in any specific USB mode. */
|
||||
USB_MODE_Device = 1, /**< Indicates that the controller is currently initialized in USB Device mode. */
|
||||
};
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Function Prototypes: */
|
||||
#if defined(__INCLUDE_FROM_USB_CONTROLLER_C)
|
||||
static void USB_Init_Device(void);
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Enable(void)
|
||||
{
|
||||
USB.CTRLA |= (USB_ENABLE_bm | USB_STFRNUM_bm | USB_MAXEP_gm);
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Disable(void)
|
||||
{
|
||||
USB.CTRLA &= ~USB_ENABLE_bm;
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Reset(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Reset(void)
|
||||
{
|
||||
USB.CTRLA &= ~USB_ENABLE_bm;
|
||||
USB.CTRLA |= USB_ENABLE_bm;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Controller definitions for the AVR XMEGA microcontrollers.
|
||||
* \copydetails Group_USBManagement_XMEGA
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USBManagement
|
||||
* \defgroup Group_USBManagement_XMEGA USB Interface Management (XMEGA)
|
||||
* \brief USB Controller definitions for the AVR XMEGA microcontrollers.
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the setup and management of the USB interface.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBCONTROLLER_XMEGA_H__
|
||||
#define __USBCONTROLLER_XMEGA_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
#include "../USBMode.h"
|
||||
#include "../Events.h"
|
||||
#include "../USBTask.h"
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* External Variables: */
|
||||
extern USB_EP_TABLE_t USB_EndpointTable;
|
||||
#endif
|
||||
|
||||
/* Includes: */
|
||||
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
|
||||
#include "../Device.h"
|
||||
#include "../Endpoint.h"
|
||||
#include "../DeviceStandardReq.h"
|
||||
#include "../EndpointStream.h"
|
||||
#endif
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks and Defines: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
#if !defined(F_USB)
|
||||
#error F_USB is not defined. You must define F_USB to the frequency of the unprescaled USB controller clock in your project makefile.
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name USB Controller Option Masks */
|
||||
//@{
|
||||
/** Sets the USB bus interrupt priority level to be low priority. The USB bus interrupt is used for Start of Frame events, bus suspend
|
||||
* and resume events, bus reset events and other events related to the management of the USB bus.
|
||||
*/
|
||||
#define USB_OPT_BUSEVENT_PRILOW ((0 << 1) | (0 << 1))
|
||||
|
||||
/** Sets the USB bus interrupt priority level to be medium priority. The USB bus interrupt is used for Start of Frame events, bus suspend
|
||||
* and resume events, bus reset events and other events related to the management of the USB bus.
|
||||
*/
|
||||
#define USB_OPT_BUSEVENT_PRIMED ((0 << 1) | (1 << 1))
|
||||
|
||||
/** Sets the USB bus interrupt priority level to be high priority. The USB bus interrupt is used for Start of Frame events, bus suspend
|
||||
* and resume events, bus reset events and other events related to the management of the USB bus.
|
||||
*/
|
||||
#define USB_OPT_BUSEVENT_PRIHIGH ((1 << 1) | (0 << 1))
|
||||
//@}
|
||||
|
||||
/** \name Endpoint/Pipe Type Masks */
|
||||
//@{
|
||||
/** Mask for a CONTROL type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_CONTROL 0x00
|
||||
|
||||
/** Mask for an ISOCHRONOUS type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_ISOCHRONOUS 0x01
|
||||
|
||||
/** Mask for a BULK type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_BULK 0x02
|
||||
|
||||
/** Mask for an INTERRUPT type endpoint or pipe.
|
||||
*
|
||||
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
|
||||
*/
|
||||
#define EP_TYPE_INTERRUPT 0x03
|
||||
//@}
|
||||
|
||||
#if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)
|
||||
/** Constant for the maximum software timeout period of the USB data stream transfer functions
|
||||
* (both control and standard) when in either device or host mode. If the next packet of a stream
|
||||
* is not received or acknowledged within this time period, the stream function will fail.
|
||||
*
|
||||
* This value may be overridden in the user project makefile as the value of the
|
||||
* \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch.
|
||||
*/
|
||||
#define USB_STREAM_TIMEOUT_MS 100
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Detaches the device from the USB bus. This has the effect of removing the device from any
|
||||
* attached host, ceasing USB communications. If no host is present, this prevents any host from
|
||||
* enumerating the device once attached until \ref USB_Attach() is called.
|
||||
*/
|
||||
static inline void USB_Detach(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Detach(void)
|
||||
{
|
||||
USB.CTRLB &= ~USB_ATTACH_bm;
|
||||
}
|
||||
|
||||
/** Attaches the device to the USB bus. This announces the device's presence to any attached
|
||||
* USB host, starting the enumeration process. If no host is present, attaching the device
|
||||
* will allow for enumeration once a host is connected to the device.
|
||||
*
|
||||
* This is inexplicably also required for proper operation while in host mode, to enable the
|
||||
* attachment of a device to the host. This is despite the bit being located in the device-mode
|
||||
* register and despite the datasheet making no mention of its requirement in host mode.
|
||||
*/
|
||||
static inline void USB_Attach(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Attach(void)
|
||||
{
|
||||
USB.CTRLB |= USB_ATTACH_bm;
|
||||
}
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Main function to initialize and start the USB interface. Once active, the USB interface will
|
||||
* allow for device connection to a host when in device mode, or for device enumeration while in
|
||||
* host mode.
|
||||
*
|
||||
* As the USB library relies on interrupts for the device and host mode enumeration processes,
|
||||
* the user must enable global interrupts before or shortly after this function is called. In
|
||||
* device mode, interrupts must be enabled within 500ms of this function being called to ensure
|
||||
* that the host does not time out whilst enumerating the device. In host mode, interrupts may be
|
||||
* enabled at the application's leisure however enumeration will not begin of an attached device
|
||||
* until after this has occurred.
|
||||
*
|
||||
* Calling this function when the USB interface is already initialized will cause a complete USB
|
||||
* interface reset and re-enumeration.
|
||||
*
|
||||
* \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to, a value
|
||||
* from the \ref USB_Modes_t enum.
|
||||
*
|
||||
* \param[in] Options Mask indicating the options which should be used when initializing the USB
|
||||
* interface to control the USB interface's behaviour. This should be comprised of
|
||||
* a \c USB_OPT_REG_* mask to control the regulator, a \c USB_OPT_*_PLL mask to control the
|
||||
* PLL, and a \c USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device
|
||||
* mode speed.
|
||||
*
|
||||
* \note To reduce the FLASH requirements of the library if only device or host mode is required,
|
||||
* the mode can be statically set in the project makefile by defining the token \c USB_DEVICE_ONLY
|
||||
* (for device mode) or \c USB_HOST_ONLY (for host mode), passing the token to the compiler
|
||||
* via the -D switch. If the mode is statically set, this parameter does not exist in the
|
||||
* function prototype.
|
||||
* \n\n
|
||||
*
|
||||
* \note To reduce the FLASH requirements of the library if only fixed settings are are required,
|
||||
* the options may be set statically in the same manner as the mode (see the Mode parameter of
|
||||
* this function). To statically set the USB options, pass in the \c USE_STATIC_OPTIONS token,
|
||||
* defined to the appropriate options masks. When the options are statically set, this
|
||||
* parameter does not exist in the function prototype.
|
||||
* \n\n
|
||||
*
|
||||
* \note The mode parameter does not exist on devices where only one mode is possible, such as USB
|
||||
* AVR models which only implement the USB device mode in hardware.
|
||||
*
|
||||
* \see \ref Group_Device for the \c USB_DEVICE_OPT_* masks.
|
||||
*/
|
||||
void USB_Init(
|
||||
#if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
|
||||
const uint8_t Mode
|
||||
#endif
|
||||
|
||||
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__)
|
||||
,
|
||||
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
|
||||
void
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
|
||||
const uint8_t Options
|
||||
#endif
|
||||
);
|
||||
|
||||
/** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO
|
||||
* memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface
|
||||
* is restarted with the \ref USB_Init() function.
|
||||
*/
|
||||
void USB_Disable(void);
|
||||
|
||||
/** Resets the interface, when already initialized. This will re-enumerate the device if already connected
|
||||
* to a host, or re-enumerate an already attached device when in host mode.
|
||||
*/
|
||||
void USB_ResetInterface(void);
|
||||
|
||||
/* Global Variables: */
|
||||
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__)
|
||||
/** Indicates the mode that the USB interface is currently initialized to, a value from the
|
||||
* \ref USB_Modes_t enum.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
* \n\n
|
||||
*
|
||||
* \note When the controller is initialized into UID auto-detection mode, this variable will hold the
|
||||
* currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller
|
||||
* is fixed into a specific mode (either through the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY compile time
|
||||
* options, or a limitation of the USB controller in the chosen device model) this will evaluate to
|
||||
* a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the
|
||||
* USB interface is not initialized.
|
||||
*/
|
||||
extern volatile uint8_t USB_CurrentMode;
|
||||
#elif defined(USB_DEVICE_ONLY)
|
||||
#define USB_CurrentMode USB_MODE_Device
|
||||
#endif
|
||||
|
||||
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
|
||||
/** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init()
|
||||
* was called. This value will be one of the \c USB_MODE_* masks defined elsewhere in this module.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
*/
|
||||
extern volatile uint8_t USB_Options;
|
||||
#elif defined(USE_STATIC_OPTIONS)
|
||||
#define USB_Options USE_STATIC_OPTIONS
|
||||
#endif
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible USB controller modes, for initialization via \ref USB_Init() and indication back to the
|
||||
* user application via \ref USB_CurrentMode.
|
||||
*/
|
||||
enum USB_Modes_t
|
||||
{
|
||||
USB_MODE_None = 0, /**< Indicates that the controller is currently not initialized in any specific USB mode. */
|
||||
USB_MODE_Device = 1, /**< Indicates that the controller is currently initialized in USB Device mode. */
|
||||
};
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Function Prototypes: */
|
||||
#if defined(__INCLUDE_FROM_USB_CONTROLLER_C)
|
||||
static void USB_Init_Device(void);
|
||||
#endif
|
||||
|
||||
/* Inline Functions: */
|
||||
static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Enable(void)
|
||||
{
|
||||
USB.CTRLA |= (USB_ENABLE_bm | USB_STFRNUM_bm | USB_MAXEP_gm);
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Disable(void)
|
||||
{
|
||||
USB.CTRLA &= ~USB_ENABLE_bm;
|
||||
}
|
||||
|
||||
static inline void USB_Controller_Reset(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_Controller_Reset(void)
|
||||
{
|
||||
USB.CTRLA &= ~USB_ENABLE_bm;
|
||||
USB.CTRLA |= USB_ENABLE_bm;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1,100 +1,100 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
void USB_INT_DisableAllInterrupts(void)
|
||||
{
|
||||
USB.INTCTRLA = 0;
|
||||
USB.INTCTRLB = 0;
|
||||
}
|
||||
|
||||
void USB_INT_ClearAllInterrupts(void)
|
||||
{
|
||||
USB.INTFLAGSACLR = 0xFF;
|
||||
USB.INTFLAGSBCLR = 0xFF;
|
||||
}
|
||||
|
||||
ISR(USB_BUSEVENT_vect)
|
||||
{
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_SOFI);
|
||||
|
||||
EVENT_USB_Device_StartOfFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Suspend))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_BUSEVENTI_Suspend);
|
||||
|
||||
#if !defined(NO_LIMITED_CONTROLLER_CONNECT)
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
EVENT_USB_Device_Disconnect();
|
||||
#else
|
||||
USB_DeviceState = DEVICE_STATE_Suspended;
|
||||
EVENT_USB_Device_Suspend();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Resume))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_BUSEVENTI_Resume);
|
||||
|
||||
if (USB_Device_ConfigurationNumber)
|
||||
USB_DeviceState = DEVICE_STATE_Configured;
|
||||
else
|
||||
USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
|
||||
|
||||
#if !defined(NO_LIMITED_CONTROLLER_CONNECT)
|
||||
EVENT_USB_Device_Connect();
|
||||
#else
|
||||
EVENT_USB_Device_WakeUp();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Reset))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_BUSEVENTI_Reset);
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Default;
|
||||
USB_Device_ConfigurationNumber = 0;
|
||||
|
||||
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
|
||||
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
EVENT_USB_Device_Reset();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#define __INCLUDE_FROM_USB_DRIVER
|
||||
#include "../USBInterrupt.h"
|
||||
|
||||
void USB_INT_DisableAllInterrupts(void)
|
||||
{
|
||||
USB.INTCTRLA = 0;
|
||||
USB.INTCTRLB = 0;
|
||||
}
|
||||
|
||||
void USB_INT_ClearAllInterrupts(void)
|
||||
{
|
||||
USB.INTFLAGSACLR = 0xFF;
|
||||
USB.INTFLAGSBCLR = 0xFF;
|
||||
}
|
||||
|
||||
ISR(USB_BUSEVENT_vect)
|
||||
{
|
||||
#if !defined(NO_SOF_EVENTS)
|
||||
if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_SOFI);
|
||||
|
||||
EVENT_USB_Device_StartOfFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Suspend))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_BUSEVENTI_Suspend);
|
||||
|
||||
#if !defined(NO_LIMITED_CONTROLLER_CONNECT)
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
EVENT_USB_Device_Disconnect();
|
||||
#else
|
||||
USB_DeviceState = DEVICE_STATE_Suspended;
|
||||
EVENT_USB_Device_Suspend();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Resume))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_BUSEVENTI_Resume);
|
||||
|
||||
if (USB_Device_ConfigurationNumber)
|
||||
USB_DeviceState = DEVICE_STATE_Configured;
|
||||
else
|
||||
USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
|
||||
|
||||
#if !defined(NO_LIMITED_CONTROLLER_CONNECT)
|
||||
EVENT_USB_Device_Connect();
|
||||
#else
|
||||
EVENT_USB_Device_WakeUp();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Reset))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_BUSEVENTI_Reset);
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Default;
|
||||
USB_Device_ConfigurationNumber = 0;
|
||||
|
||||
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
|
||||
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
EVENT_USB_Device_Reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,166 +1,166 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Controller Interrupt definitions for the AVR XMEGA microcontrollers.
|
||||
*
|
||||
* This file contains definitions required for the correct handling of low level USB service routine interrupts
|
||||
* from the USB controller.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
#ifndef __USBINTERRUPT_XMEGA_H__
|
||||
#define __USBINTERRUPT_XMEGA_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Enums: */
|
||||
enum USB_Interrupts_t
|
||||
{
|
||||
USB_INT_BUSEVENTI = 1,
|
||||
USB_INT_BUSEVENTI_Suspend = 2,
|
||||
USB_INT_BUSEVENTI_Resume = 3,
|
||||
USB_INT_BUSEVENTI_Reset = 4,
|
||||
USB_INT_SOFI = 5,
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Enable(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI:
|
||||
USB.INTCTRLA |= USB_BUSEVIE_bm;
|
||||
return;
|
||||
case USB_INT_SOFI:
|
||||
USB.INTCTRLA |= USB_SOFIE_bm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Disable(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI:
|
||||
USB.INTCTRLA &= ~USB_BUSEVIE_bm;
|
||||
return;
|
||||
case USB_INT_SOFI:
|
||||
USB.INTCTRLA &= ~USB_SOFIE_bm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Clear(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI_Suspend:
|
||||
USB.INTFLAGSACLR = USB_SUSPENDIF_bm;
|
||||
return;
|
||||
case USB_INT_BUSEVENTI_Resume:
|
||||
USB.INTFLAGSACLR = USB_RESUMEIF_bm;
|
||||
return;
|
||||
case USB_INT_BUSEVENTI_Reset:
|
||||
USB.INTFLAGSACLR = USB_RSTIF_bm;
|
||||
return;
|
||||
case USB_INT_SOFI:
|
||||
USB.INTFLAGSACLR = USB_SOFIF_bm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI:
|
||||
return (USB.INTCTRLA & USB_BUSEVIE_bm);
|
||||
case USB_INT_SOFI:
|
||||
return (USB.INTCTRLA & USB_SOFIE_bm);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI_Suspend:
|
||||
return (USB.INTFLAGSACLR & USB_SUSPENDIF_bm);
|
||||
case USB_INT_BUSEVENTI_Resume:
|
||||
return (USB.INTFLAGSACLR & USB_RESUMEIF_bm);
|
||||
case USB_INT_BUSEVENTI_Reset:
|
||||
return (USB.INTFLAGSACLR & USB_RSTIF_bm);
|
||||
case USB_INT_SOFI:
|
||||
return (USB.INTFLAGSACLR & USB_SOFIF_bm);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Includes: */
|
||||
#include "../USBMode.h"
|
||||
#include "../Events.h"
|
||||
#include "../USBController.h"
|
||||
|
||||
/* Function Prototypes: */
|
||||
void USB_INT_ClearAllInterrupts(void);
|
||||
void USB_INT_DisableAllInterrupts(void);
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief USB Controller Interrupt definitions for the AVR XMEGA microcontrollers.
|
||||
*
|
||||
* This file contains definitions required for the correct handling of low level USB service routine interrupts
|
||||
* from the USB controller.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
#ifndef __USBINTERRUPT_XMEGA_H__
|
||||
#define __USBINTERRUPT_XMEGA_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_USB_DRIVER)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Enums: */
|
||||
enum USB_Interrupts_t
|
||||
{
|
||||
USB_INT_BUSEVENTI = 1,
|
||||
USB_INT_BUSEVENTI_Suspend = 2,
|
||||
USB_INT_BUSEVENTI_Resume = 3,
|
||||
USB_INT_BUSEVENTI_Reset = 4,
|
||||
USB_INT_SOFI = 5,
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Enable(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI:
|
||||
USB.INTCTRLA |= USB_BUSEVIE_bm;
|
||||
return;
|
||||
case USB_INT_SOFI:
|
||||
USB.INTCTRLA |= USB_SOFIE_bm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Disable(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI:
|
||||
USB.INTCTRLA &= ~USB_BUSEVIE_bm;
|
||||
return;
|
||||
case USB_INT_SOFI:
|
||||
USB.INTCTRLA &= ~USB_SOFIE_bm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
|
||||
static inline void USB_INT_Clear(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI_Suspend:
|
||||
USB.INTFLAGSACLR = USB_SUSPENDIF_bm;
|
||||
return;
|
||||
case USB_INT_BUSEVENTI_Resume:
|
||||
USB.INTFLAGSACLR = USB_RESUMEIF_bm;
|
||||
return;
|
||||
case USB_INT_BUSEVENTI_Reset:
|
||||
USB.INTFLAGSACLR = USB_RSTIF_bm;
|
||||
return;
|
||||
case USB_INT_SOFI:
|
||||
USB.INTFLAGSACLR = USB_SOFIF_bm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI:
|
||||
return (USB.INTCTRLA & USB_BUSEVIE_bm);
|
||||
case USB_INT_SOFI:
|
||||
return (USB.INTCTRLA & USB_SOFIE_bm);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
|
||||
{
|
||||
switch (Interrupt)
|
||||
{
|
||||
case USB_INT_BUSEVENTI_Suspend:
|
||||
return (USB.INTFLAGSACLR & USB_SUSPENDIF_bm);
|
||||
case USB_INT_BUSEVENTI_Resume:
|
||||
return (USB.INTFLAGSACLR & USB_RESUMEIF_bm);
|
||||
case USB_INT_BUSEVENTI_Reset:
|
||||
return (USB.INTFLAGSACLR & USB_RSTIF_bm);
|
||||
case USB_INT_SOFI:
|
||||
return (USB.INTFLAGSACLR & USB_SOFIF_bm);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Includes: */
|
||||
#include "../USBMode.h"
|
||||
#include "../Events.h"
|
||||
#include "../USBController.h"
|
||||
|
||||
/* Function Prototypes: */
|
||||
void USB_INT_ClearAllInterrupts(void);
|
||||
void USB_INT_DisableAllInterrupts(void);
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,324 +1,324 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Module Clock Driver for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* Clock management driver for the AVR32 UC3 microcontrollers. This driver allows for the configuration
|
||||
* of the various clocks within the device to clock the various peripherals.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PlatformDrivers
|
||||
* \defgroup Group_PlatformDrivers_UC3Clocks UC3 Clock Management Driver - LUFA/Platform/UC3/ClockManagement.h
|
||||
* \brief Module Clock Driver for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* \section Sec_Dependencies Module Source Dependencies
|
||||
* The following files must be built with any user project that uses this module:
|
||||
* - None
|
||||
*
|
||||
* \section Sec_ModDescription Module Description
|
||||
* Clock management driver for the AVR32 UC3 microcontrollers. This driver allows for the configuration
|
||||
* of the various clocks within the device to clock the various peripherals.
|
||||
*
|
||||
* Usage Example:
|
||||
* \code
|
||||
* #include <LUFA/Platform/UC3/ClockManagement.h>
|
||||
*
|
||||
* void main(void)
|
||||
* {
|
||||
* // Start the master external oscillator which will be used as the main clock reference
|
||||
* AVR32CLK_StartExternalOscillator(0, EXOSC_MODE_8MHZ_OR_MORE, EXOSC_START_0CLK);
|
||||
*
|
||||
* // Start the PLL for the CPU clock, switch CPU to it
|
||||
* AVR32CLK_StartPLL(0, CLOCK_SRC_OSC0, 12000000, F_CPU);
|
||||
* AVR32CLK_SetCPUClockSource(CLOCK_SRC_PLL0, F_CPU);
|
||||
*
|
||||
* // Start the PLL for the USB Generic Clock module
|
||||
* AVR32CLK_StartPLL(1, CLOCK_SRC_OSC0, 12000000, 48000000);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _UC3_CLOCK_MANAGEMENT_H_
|
||||
#define _UC3_CLOCK_MANAGEMENT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Common/Common.h>
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Enum for the possible external oscillator types. */
|
||||
enum UC3_Extern_OSC_ClockTypes_t
|
||||
{
|
||||
EXOSC_MODE_CLOCK = AVR32_PM_OSCCTRL0_MODE_EXT_CLOCK, /**< External clock (non-crystal) mode. */
|
||||
EXOSC_MODE_900KHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G0, /**< External crystal oscillator equal to or slower than 900KHz. */
|
||||
EXOSC_MODE_3MHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G1, /**< External crystal oscillator equal to or slower than 3MHz. */
|
||||
EXOSC_MODE_8MHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G2, /**< External crystal oscillator equal to or slower than 8MHz. */
|
||||
EXOSC_MODE_8MHZ_OR_MORE = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3, /**< External crystal oscillator equal to or faster than 8MHz. */
|
||||
};
|
||||
|
||||
/** Enum for the possible external oscillator statup times. */
|
||||
enum UC3_Extern_OSC_ClockStartup_t
|
||||
{
|
||||
EXOSC_START_0CLK = AVR32_PM_OSCCTRL0_STARTUP_0_RCOSC, /**< Immediate startup, no delay. */
|
||||
EXOSC_START_64CLK = AVR32_PM_OSCCTRL0_STARTUP_64_RCOSC, /**< Wait 64 clock cyles before startup for stability. */
|
||||
EXOSC_START_128CLK = AVR32_PM_OSCCTRL0_STARTUP_128_RCOSC, /**< Wait 128 clock cyles before startup for stability. */
|
||||
EXOSC_START_2048CLK = AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC, /**< Wait 2048 clock cyles before startup for stability. */
|
||||
EXOSC_START_4096CLK = AVR32_PM_OSCCTRL0_STARTUP_4096_RCOSC, /**< Wait 4096 clock cyles before startup for stability. */
|
||||
EXOSC_START_8192CLK = AVR32_PM_OSCCTRL0_STARTUP_8192_RCOSC, /**< Wait 8192 clock cyles before startup for stability. */
|
||||
EXOSC_START_16384CLK = AVR32_PM_OSCCTRL0_STARTUP_16384_RCOSC, /**< Wait 16384 clock cyles before startup for stability. */
|
||||
};
|
||||
|
||||
/** Enum for the possible module clock sources. */
|
||||
enum UC3_System_ClockSource_t
|
||||
{
|
||||
CLOCK_SRC_SLOW_CLK = 0, /**< Clock sourced from the internal slow clock. */
|
||||
CLOCK_SRC_OSC0 = 1, /**< Clock sourced from the Oscillator 0 clock. */
|
||||
CLOCK_SRC_OSC1 = 2, /**< Clock sourced from the Oscillator 1 clock. */
|
||||
CLOCK_SRC_PLL0 = 3, /**< Clock sourced from the PLL 0 clock. */
|
||||
CLOCK_SRC_PLL1 = 4, /**< Clock sourced from the PLL 1 clock. */
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Starts the given external oscillator of the UC3 microcontroller, with the given options. This routine blocks until
|
||||
* the oscillator is ready for use.
|
||||
*
|
||||
* \param[in] Channel Index of the external oscillator to start.
|
||||
* \param[in] Type Type of clock attached to the given oscillator channel, a value from \ref UC3_Extern_OSC_ClockTypes_t.
|
||||
* \param[in] Startup Statup time of the external oscillator, a value from \ref UC3_Extern_OSC_ClockStartup_t.
|
||||
*
|
||||
* \return Boolean \c true if the external oscillator was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t Channel,
|
||||
const uint8_t Type,
|
||||
const uint8_t Startup) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t Channel,
|
||||
const uint8_t Type,
|
||||
const uint8_t Startup)
|
||||
{
|
||||
switch (Channel)
|
||||
{
|
||||
case 0:
|
||||
AVR32_PM.OSCCTRL0.startup = Startup;
|
||||
AVR32_PM.OSCCTRL0.mode = Type;
|
||||
break;
|
||||
case 1:
|
||||
AVR32_PM.OSCCTRL1.startup = Startup;
|
||||
AVR32_PM.OSCCTRL1.mode = Type;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
AVR32_PM.mcctrl |= (1 << (AVR32_PM_MCCTRL_OSC0EN_OFFSET + Channel));
|
||||
|
||||
while (!(AVR32_PM.poscsr & (1 << (AVR32_PM_POSCSR_OSC0RDY_OFFSET + Channel))));
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the given external oscillator of the UC3 microcontroller.
|
||||
*
|
||||
* \param[in] Channel Index of the external oscillator to stop.
|
||||
*/
|
||||
static inline void AVR32CLK_StopExternalOscillator(const uint8_t Channel) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopExternalOscillator(const uint8_t Channel)
|
||||
{
|
||||
AVR32_PM.mcctrl &= ~(1 << (AVR32_PM_MCCTRL_OSC0EN_OFFSET + Channel));
|
||||
}
|
||||
|
||||
/** Starts the given PLL of the UC3 microcontroller, with the given options. This routine blocks until the PLL is ready for use.
|
||||
*
|
||||
* \note The output frequency must be equal to or greater than the source frequency.
|
||||
*
|
||||
* \param[in] Channel Index of the PLL to start.
|
||||
* \param[in] Source Clock source for the PLL, a value from \ref UC3_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the PLL's clock source, in Hz.
|
||||
* \param[in] Frequency Target frequency of the PLL's output.
|
||||
*
|
||||
* \return Boolean \c true if the PLL was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartPLL(const uint8_t Channel,
|
||||
const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartPLL(const uint8_t Channel,
|
||||
const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency)
|
||||
{
|
||||
if (SourceFreq > Frequency)
|
||||
return false;
|
||||
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_OSC0:
|
||||
AVR32_PM.PLL[Channel].pllosc = 0;
|
||||
break;
|
||||
case CLOCK_SRC_OSC1:
|
||||
AVR32_PM.PLL[Channel].pllosc = 1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
AVR32_PM.PLL[Channel].pllmul = (Frequency / SourceFreq) ? (((Frequency / SourceFreq) - 1) / 2) : 0;
|
||||
AVR32_PM.PLL[Channel].plldiv = 0;
|
||||
AVR32_PM.PLL[Channel].pllen = true;
|
||||
|
||||
while (!(AVR32_PM.poscsr & (1 << (AVR32_PM_POSCSR_LOCK0_OFFSET + Channel))));
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the given PLL of the UC3 microcontroller.
|
||||
*
|
||||
* \param[in] Channel Index of the PLL to stop.
|
||||
*/
|
||||
static inline void AVR32CLK_StopPLL(const uint8_t Channel) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopPLL(const uint8_t Channel)
|
||||
{
|
||||
AVR32_PM.PLL[Channel].pllen = false;
|
||||
}
|
||||
|
||||
/** Starts the given Generic Clock of the UC3 microcontroller, with the given options.
|
||||
*
|
||||
* \param[in] Channel Index of the Generic Clock to start.
|
||||
* \param[in] Source Clock source for the Generic Clock, a value from \ref UC3_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the Generic Clock's clock source, in Hz.
|
||||
* \param[in] Frequency Target frequency of the Generic Clock's output.
|
||||
*
|
||||
* \return Boolean \c true if the Generic Clock was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartGenericClock(const uint8_t Channel,
|
||||
const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartGenericClock(const uint8_t Channel,
|
||||
const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency)
|
||||
{
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_OSC0:
|
||||
AVR32_PM.GCCTRL[Channel].pllsel = false;
|
||||
AVR32_PM.GCCTRL[Channel].oscsel = 0;
|
||||
break;
|
||||
case CLOCK_SRC_OSC1:
|
||||
AVR32_PM.GCCTRL[Channel].pllsel = false;
|
||||
AVR32_PM.GCCTRL[Channel].oscsel = 1;
|
||||
break;
|
||||
case CLOCK_SRC_PLL0:
|
||||
AVR32_PM.GCCTRL[Channel].pllsel = true;
|
||||
AVR32_PM.GCCTRL[Channel].oscsel = 0;
|
||||
break;
|
||||
case CLOCK_SRC_PLL1:
|
||||
AVR32_PM.GCCTRL[Channel].pllsel = true;
|
||||
AVR32_PM.GCCTRL[Channel].oscsel = 1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SourceFreq < Frequency)
|
||||
return false;
|
||||
|
||||
AVR32_PM.GCCTRL[Channel].diven = (SourceFreq > Frequency) ? true : false;
|
||||
AVR32_PM.GCCTRL[Channel].div = (((SourceFreq / Frequency) - 1) / 2);
|
||||
AVR32_PM.GCCTRL[Channel].cen = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the given generic clock of the UC3 microcontroller.
|
||||
*
|
||||
* \param[in] Channel Index of the generic clock to stop.
|
||||
*/
|
||||
static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopGenericClock(const uint8_t Channel)
|
||||
{
|
||||
AVR32_PM.GCCTRL[Channel].cen = false;
|
||||
}
|
||||
|
||||
/** Sets the clock source for the main microcontroller core. The given clock source should be configured
|
||||
* and ready for use before this function is called.
|
||||
*
|
||||
* This function will configure the FLASH controller's wait states automatically to suit the given clock source.
|
||||
*
|
||||
* \param[in] Source Clock source for the CPU core, a value from \ref UC3_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the CPU core's clock source, in Hz.
|
||||
*
|
||||
* \return Boolean \c true if the CPU core clock was sucessfully altered, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source,
|
||||
const uint32_t SourceFreq) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source,
|
||||
const uint32_t SourceFreq)
|
||||
{
|
||||
AVR32_FLASHC.FCR.fws = (SourceFreq > 30000000) ? true : false;
|
||||
|
||||
switch (Source)
|
||||
{
|
||||
#if defined(AVR32_PM_MCCTRL_MCSEL_SLOW)
|
||||
case CLOCK_SRC_SLOW_CLK:
|
||||
AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_SLOW;
|
||||
break;
|
||||
#endif
|
||||
#if defined(AVR32_PM_MCCTRL_MCSEL_OSC0)
|
||||
case CLOCK_SRC_OSC0:
|
||||
AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_OSC0;
|
||||
break;
|
||||
#endif
|
||||
#if defined(AVR32_PM_MCCTRL_MCSEL_PLL0)
|
||||
case CLOCK_SRC_PLL0:
|
||||
AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_PLL0;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Module Clock Driver for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* Clock management driver for the AVR32 UC3 microcontrollers. This driver allows for the configuration
|
||||
* of the various clocks within the device to clock the various peripherals.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PlatformDrivers
|
||||
* \defgroup Group_PlatformDrivers_UC3Clocks UC3 Clock Management Driver - LUFA/Platform/UC3/ClockManagement.h
|
||||
* \brief Module Clock Driver for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* \section Sec_Dependencies Module Source Dependencies
|
||||
* The following files must be built with any user project that uses this module:
|
||||
* - None
|
||||
*
|
||||
* \section Sec_ModDescription Module Description
|
||||
* Clock management driver for the AVR32 UC3 microcontrollers. This driver allows for the configuration
|
||||
* of the various clocks within the device to clock the various peripherals.
|
||||
*
|
||||
* Usage Example:
|
||||
* \code
|
||||
* #include <LUFA/Platform/UC3/ClockManagement.h>
|
||||
*
|
||||
* void main(void)
|
||||
* {
|
||||
* // Start the master external oscillator which will be used as the main clock reference
|
||||
* AVR32CLK_StartExternalOscillator(0, EXOSC_MODE_8MHZ_OR_MORE, EXOSC_START_0CLK);
|
||||
*
|
||||
* // Start the PLL for the CPU clock, switch CPU to it
|
||||
* AVR32CLK_StartPLL(0, CLOCK_SRC_OSC0, 12000000, F_CPU);
|
||||
* AVR32CLK_SetCPUClockSource(CLOCK_SRC_PLL0, F_CPU);
|
||||
*
|
||||
* // Start the PLL for the USB Generic Clock module
|
||||
* AVR32CLK_StartPLL(1, CLOCK_SRC_OSC0, 12000000, 48000000);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _UC3_CLOCK_MANAGEMENT_H_
|
||||
#define _UC3_CLOCK_MANAGEMENT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Common/Common.h>
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Enum for the possible external oscillator types. */
|
||||
enum UC3_Extern_OSC_ClockTypes_t
|
||||
{
|
||||
EXOSC_MODE_CLOCK = AVR32_PM_OSCCTRL0_MODE_EXT_CLOCK, /**< External clock (non-crystal) mode. */
|
||||
EXOSC_MODE_900KHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G0, /**< External crystal oscillator equal to or slower than 900KHz. */
|
||||
EXOSC_MODE_3MHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G1, /**< External crystal oscillator equal to or slower than 3MHz. */
|
||||
EXOSC_MODE_8MHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G2, /**< External crystal oscillator equal to or slower than 8MHz. */
|
||||
EXOSC_MODE_8MHZ_OR_MORE = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3, /**< External crystal oscillator equal to or faster than 8MHz. */
|
||||
};
|
||||
|
||||
/** Enum for the possible external oscillator statup times. */
|
||||
enum UC3_Extern_OSC_ClockStartup_t
|
||||
{
|
||||
EXOSC_START_0CLK = AVR32_PM_OSCCTRL0_STARTUP_0_RCOSC, /**< Immediate startup, no delay. */
|
||||
EXOSC_START_64CLK = AVR32_PM_OSCCTRL0_STARTUP_64_RCOSC, /**< Wait 64 clock cyles before startup for stability. */
|
||||
EXOSC_START_128CLK = AVR32_PM_OSCCTRL0_STARTUP_128_RCOSC, /**< Wait 128 clock cyles before startup for stability. */
|
||||
EXOSC_START_2048CLK = AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC, /**< Wait 2048 clock cyles before startup for stability. */
|
||||
EXOSC_START_4096CLK = AVR32_PM_OSCCTRL0_STARTUP_4096_RCOSC, /**< Wait 4096 clock cyles before startup for stability. */
|
||||
EXOSC_START_8192CLK = AVR32_PM_OSCCTRL0_STARTUP_8192_RCOSC, /**< Wait 8192 clock cyles before startup for stability. */
|
||||
EXOSC_START_16384CLK = AVR32_PM_OSCCTRL0_STARTUP_16384_RCOSC, /**< Wait 16384 clock cyles before startup for stability. */
|
||||
};
|
||||
|
||||
/** Enum for the possible module clock sources. */
|
||||
enum UC3_System_ClockSource_t
|
||||
{
|
||||
CLOCK_SRC_SLOW_CLK = 0, /**< Clock sourced from the internal slow clock. */
|
||||
CLOCK_SRC_OSC0 = 1, /**< Clock sourced from the Oscillator 0 clock. */
|
||||
CLOCK_SRC_OSC1 = 2, /**< Clock sourced from the Oscillator 1 clock. */
|
||||
CLOCK_SRC_PLL0 = 3, /**< Clock sourced from the PLL 0 clock. */
|
||||
CLOCK_SRC_PLL1 = 4, /**< Clock sourced from the PLL 1 clock. */
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Starts the given external oscillator of the UC3 microcontroller, with the given options. This routine blocks until
|
||||
* the oscillator is ready for use.
|
||||
*
|
||||
* \param[in] Channel Index of the external oscillator to start.
|
||||
* \param[in] Type Type of clock attached to the given oscillator channel, a value from \ref UC3_Extern_OSC_ClockTypes_t.
|
||||
* \param[in] Startup Statup time of the external oscillator, a value from \ref UC3_Extern_OSC_ClockStartup_t.
|
||||
*
|
||||
* \return Boolean \c true if the external oscillator was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t Channel,
|
||||
const uint8_t Type,
|
||||
const uint8_t Startup) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t Channel,
|
||||
const uint8_t Type,
|
||||
const uint8_t Startup)
|
||||
{
|
||||
switch (Channel)
|
||||
{
|
||||
case 0:
|
||||
AVR32_PM.OSCCTRL0.startup = Startup;
|
||||
AVR32_PM.OSCCTRL0.mode = Type;
|
||||
break;
|
||||
case 1:
|
||||
AVR32_PM.OSCCTRL1.startup = Startup;
|
||||
AVR32_PM.OSCCTRL1.mode = Type;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
AVR32_PM.mcctrl |= (1 << (AVR32_PM_MCCTRL_OSC0EN_OFFSET + Channel));
|
||||
|
||||
while (!(AVR32_PM.poscsr & (1 << (AVR32_PM_POSCSR_OSC0RDY_OFFSET + Channel))));
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the given external oscillator of the UC3 microcontroller.
|
||||
*
|
||||
* \param[in] Channel Index of the external oscillator to stop.
|
||||
*/
|
||||
static inline void AVR32CLK_StopExternalOscillator(const uint8_t Channel) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopExternalOscillator(const uint8_t Channel)
|
||||
{
|
||||
AVR32_PM.mcctrl &= ~(1 << (AVR32_PM_MCCTRL_OSC0EN_OFFSET + Channel));
|
||||
}
|
||||
|
||||
/** Starts the given PLL of the UC3 microcontroller, with the given options. This routine blocks until the PLL is ready for use.
|
||||
*
|
||||
* \note The output frequency must be equal to or greater than the source frequency.
|
||||
*
|
||||
* \param[in] Channel Index of the PLL to start.
|
||||
* \param[in] Source Clock source for the PLL, a value from \ref UC3_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the PLL's clock source, in Hz.
|
||||
* \param[in] Frequency Target frequency of the PLL's output.
|
||||
*
|
||||
* \return Boolean \c true if the PLL was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartPLL(const uint8_t Channel,
|
||||
const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartPLL(const uint8_t Channel,
|
||||
const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency)
|
||||
{
|
||||
if (SourceFreq > Frequency)
|
||||
return false;
|
||||
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_OSC0:
|
||||
AVR32_PM.PLL[Channel].pllosc = 0;
|
||||
break;
|
||||
case CLOCK_SRC_OSC1:
|
||||
AVR32_PM.PLL[Channel].pllosc = 1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
AVR32_PM.PLL[Channel].pllmul = (Frequency / SourceFreq) ? (((Frequency / SourceFreq) - 1) / 2) : 0;
|
||||
AVR32_PM.PLL[Channel].plldiv = 0;
|
||||
AVR32_PM.PLL[Channel].pllen = true;
|
||||
|
||||
while (!(AVR32_PM.poscsr & (1 << (AVR32_PM_POSCSR_LOCK0_OFFSET + Channel))));
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the given PLL of the UC3 microcontroller.
|
||||
*
|
||||
* \param[in] Channel Index of the PLL to stop.
|
||||
*/
|
||||
static inline void AVR32CLK_StopPLL(const uint8_t Channel) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopPLL(const uint8_t Channel)
|
||||
{
|
||||
AVR32_PM.PLL[Channel].pllen = false;
|
||||
}
|
||||
|
||||
/** Starts the given Generic Clock of the UC3 microcontroller, with the given options.
|
||||
*
|
||||
* \param[in] Channel Index of the Generic Clock to start.
|
||||
* \param[in] Source Clock source for the Generic Clock, a value from \ref UC3_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the Generic Clock's clock source, in Hz.
|
||||
* \param[in] Frequency Target frequency of the Generic Clock's output.
|
||||
*
|
||||
* \return Boolean \c true if the Generic Clock was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartGenericClock(const uint8_t Channel,
|
||||
const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartGenericClock(const uint8_t Channel,
|
||||
const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency)
|
||||
{
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_OSC0:
|
||||
AVR32_PM.GCCTRL[Channel].pllsel = false;
|
||||
AVR32_PM.GCCTRL[Channel].oscsel = 0;
|
||||
break;
|
||||
case CLOCK_SRC_OSC1:
|
||||
AVR32_PM.GCCTRL[Channel].pllsel = false;
|
||||
AVR32_PM.GCCTRL[Channel].oscsel = 1;
|
||||
break;
|
||||
case CLOCK_SRC_PLL0:
|
||||
AVR32_PM.GCCTRL[Channel].pllsel = true;
|
||||
AVR32_PM.GCCTRL[Channel].oscsel = 0;
|
||||
break;
|
||||
case CLOCK_SRC_PLL1:
|
||||
AVR32_PM.GCCTRL[Channel].pllsel = true;
|
||||
AVR32_PM.GCCTRL[Channel].oscsel = 1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SourceFreq < Frequency)
|
||||
return false;
|
||||
|
||||
AVR32_PM.GCCTRL[Channel].diven = (SourceFreq > Frequency) ? true : false;
|
||||
AVR32_PM.GCCTRL[Channel].div = (((SourceFreq / Frequency) - 1) / 2);
|
||||
AVR32_PM.GCCTRL[Channel].cen = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the given generic clock of the UC3 microcontroller.
|
||||
*
|
||||
* \param[in] Channel Index of the generic clock to stop.
|
||||
*/
|
||||
static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopGenericClock(const uint8_t Channel)
|
||||
{
|
||||
AVR32_PM.GCCTRL[Channel].cen = false;
|
||||
}
|
||||
|
||||
/** Sets the clock source for the main microcontroller core. The given clock source should be configured
|
||||
* and ready for use before this function is called.
|
||||
*
|
||||
* This function will configure the FLASH controller's wait states automatically to suit the given clock source.
|
||||
*
|
||||
* \param[in] Source Clock source for the CPU core, a value from \ref UC3_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the CPU core's clock source, in Hz.
|
||||
*
|
||||
* \return Boolean \c true if the CPU core clock was sucessfully altered, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source,
|
||||
const uint32_t SourceFreq) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source,
|
||||
const uint32_t SourceFreq)
|
||||
{
|
||||
AVR32_FLASHC.FCR.fws = (SourceFreq > 30000000) ? true : false;
|
||||
|
||||
switch (Source)
|
||||
{
|
||||
#if defined(AVR32_PM_MCCTRL_MCSEL_SLOW)
|
||||
case CLOCK_SRC_SLOW_CLK:
|
||||
AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_SLOW;
|
||||
break;
|
||||
#endif
|
||||
#if defined(AVR32_PM_MCCTRL_MCSEL_OSC0)
|
||||
case CLOCK_SRC_OSC0:
|
||||
AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_OSC0;
|
||||
break;
|
||||
#endif
|
||||
#if defined(AVR32_PM_MCCTRL_MCSEL_PLL0)
|
||||
case CLOCK_SRC_PLL0:
|
||||
AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_PLL0;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,125 +1,125 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#include <avr32/io.h>
|
||||
|
||||
.section .exception_handlers, "ax", @progbits
|
||||
|
||||
// ================= EXCEPTION TABLE ================
|
||||
.balign 0x200
|
||||
.global EVBA_Table
|
||||
EVBA_Table:
|
||||
|
||||
.org 0x000
|
||||
Exception_Unrecoverable_Exception:
|
||||
rjmp $
|
||||
.org 0x004
|
||||
Exception_TLB_Multiple_Hit:
|
||||
rjmp $
|
||||
.org 0x008
|
||||
Exception_Bus_Error_Data_Fetch:
|
||||
rjmp $
|
||||
.org 0x00C
|
||||
Exception_Bus_Error_Instruction_Fetch:
|
||||
rjmp $
|
||||
.org 0x010
|
||||
Exception_NMI:
|
||||
rjmp $
|
||||
.org 0x014
|
||||
Exception_Instruction_Address:
|
||||
rjmp $
|
||||
.org 0x018
|
||||
Exception_ITLB_Protection:
|
||||
rjmp $
|
||||
.org 0x01C
|
||||
Exception_OCD_Breakpoint:
|
||||
rjmp $
|
||||
.org 0x020
|
||||
Exception_Illegal_Opcode:
|
||||
rjmp $
|
||||
.org 0x024
|
||||
Exception_Unimplemented_Instruction:
|
||||
rjmp $
|
||||
.org 0x028
|
||||
Exception_Privilege_Violation:
|
||||
rjmp $
|
||||
.org 0x02C
|
||||
Exception_Floating_Point:
|
||||
rjmp $
|
||||
.org 0x030
|
||||
Exception_Coprocessor_Absent:
|
||||
rjmp $
|
||||
.org 0x034
|
||||
Exception_Data_Address_Read:
|
||||
rjmp $
|
||||
.org 0x038
|
||||
Exception_Data_Address_Write:
|
||||
rjmp $
|
||||
.org 0x03C
|
||||
Exception_DTLB_Protection_Read:
|
||||
rjmp $
|
||||
.org 0x040
|
||||
Exception_DTLB_Protection_Write:
|
||||
rjmp $
|
||||
.org 0x044
|
||||
Exception_DTLB_Modified:
|
||||
rjmp $
|
||||
.org 0x050
|
||||
Exception_ITLB_Miss:
|
||||
rjmp $
|
||||
.org 0x060
|
||||
Exception_DTLB_Miss_Read:
|
||||
rjmp $
|
||||
.org 0x070
|
||||
Exception_DTLB_Miss_Write:
|
||||
rjmp $
|
||||
.org 0x100
|
||||
Exception_Supervisor_Call:
|
||||
rjmp $
|
||||
// ============== END OF EXCEPTION TABLE =============
|
||||
|
||||
// ============= GENERAL INTERRUPT HANDLER ===========
|
||||
.balign 4
|
||||
.irp Level, 0, 1, 2, 3
|
||||
Exception_INT\Level:
|
||||
mov r12, \Level
|
||||
call INTC_GetInterruptHandler
|
||||
mov pc, r12
|
||||
.endr
|
||||
// ========= END OF GENERAL INTERRUPT HANDLER ========
|
||||
|
||||
// ====== GENERAL INTERRUPT HANDLER OFFSET TABLE ======
|
||||
.balign 4
|
||||
.global Autovector_Table
|
||||
Autovector_Table:
|
||||
.irp Level, 0, 1, 2, 3
|
||||
.word ((AVR32_INTC_INT0 + \Level) << AVR32_INTC_IPR_INTLEVEL_OFFSET) | (Exception_INT\Level - EVBA_Table)
|
||||
.endr
|
||||
// === END OF GENERAL INTERRUPT HANDLER OFFSET TABLE ===
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#include <avr32/io.h>
|
||||
|
||||
.section .exception_handlers, "ax", @progbits
|
||||
|
||||
// ================= EXCEPTION TABLE ================
|
||||
.balign 0x200
|
||||
.global EVBA_Table
|
||||
EVBA_Table:
|
||||
|
||||
.org 0x000
|
||||
Exception_Unrecoverable_Exception:
|
||||
rjmp $
|
||||
.org 0x004
|
||||
Exception_TLB_Multiple_Hit:
|
||||
rjmp $
|
||||
.org 0x008
|
||||
Exception_Bus_Error_Data_Fetch:
|
||||
rjmp $
|
||||
.org 0x00C
|
||||
Exception_Bus_Error_Instruction_Fetch:
|
||||
rjmp $
|
||||
.org 0x010
|
||||
Exception_NMI:
|
||||
rjmp $
|
||||
.org 0x014
|
||||
Exception_Instruction_Address:
|
||||
rjmp $
|
||||
.org 0x018
|
||||
Exception_ITLB_Protection:
|
||||
rjmp $
|
||||
.org 0x01C
|
||||
Exception_OCD_Breakpoint:
|
||||
rjmp $
|
||||
.org 0x020
|
||||
Exception_Illegal_Opcode:
|
||||
rjmp $
|
||||
.org 0x024
|
||||
Exception_Unimplemented_Instruction:
|
||||
rjmp $
|
||||
.org 0x028
|
||||
Exception_Privilege_Violation:
|
||||
rjmp $
|
||||
.org 0x02C
|
||||
Exception_Floating_Point:
|
||||
rjmp $
|
||||
.org 0x030
|
||||
Exception_Coprocessor_Absent:
|
||||
rjmp $
|
||||
.org 0x034
|
||||
Exception_Data_Address_Read:
|
||||
rjmp $
|
||||
.org 0x038
|
||||
Exception_Data_Address_Write:
|
||||
rjmp $
|
||||
.org 0x03C
|
||||
Exception_DTLB_Protection_Read:
|
||||
rjmp $
|
||||
.org 0x040
|
||||
Exception_DTLB_Protection_Write:
|
||||
rjmp $
|
||||
.org 0x044
|
||||
Exception_DTLB_Modified:
|
||||
rjmp $
|
||||
.org 0x050
|
||||
Exception_ITLB_Miss:
|
||||
rjmp $
|
||||
.org 0x060
|
||||
Exception_DTLB_Miss_Read:
|
||||
rjmp $
|
||||
.org 0x070
|
||||
Exception_DTLB_Miss_Write:
|
||||
rjmp $
|
||||
.org 0x100
|
||||
Exception_Supervisor_Call:
|
||||
rjmp $
|
||||
// ============== END OF EXCEPTION TABLE =============
|
||||
|
||||
// ============= GENERAL INTERRUPT HANDLER ===========
|
||||
.balign 4
|
||||
.irp Level, 0, 1, 2, 3
|
||||
Exception_INT\Level:
|
||||
mov r12, \Level
|
||||
call INTC_GetInterruptHandler
|
||||
mov pc, r12
|
||||
.endr
|
||||
// ========= END OF GENERAL INTERRUPT HANDLER ========
|
||||
|
||||
// ====== GENERAL INTERRUPT HANDLER OFFSET TABLE ======
|
||||
.balign 4
|
||||
.global Autovector_Table
|
||||
Autovector_Table:
|
||||
.irp Level, 0, 1, 2, 3
|
||||
.word ((AVR32_INTC_INT0 + \Level) << AVR32_INTC_IPR_INTLEVEL_OFFSET) | (Exception_INT\Level - EVBA_Table)
|
||||
.endr
|
||||
// === END OF GENERAL INTERRUPT HANDLER OFFSET TABLE ===
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#include "InterruptManagement.h"
|
||||
|
||||
/** Interrupt vector table, containing the ISR to call for each interrupt group */
|
||||
InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS];
|
||||
|
||||
/** ISR for unhandled interrupt groups */
|
||||
ISR(Unhandled_Interrupt)
|
||||
{
|
||||
for (;;);
|
||||
}
|
||||
|
||||
/** Retrieves the associated interrupt handler for the interrupt group currently being fired. This
|
||||
* is called directly from the exception handler routine before dispatching to the ISR.
|
||||
*/
|
||||
InterruptHandlerPtr_t INTC_GetInterruptHandler(const uint_reg_t InterruptLevel)
|
||||
{
|
||||
return InterruptHandlers[AVR32_INTC.icr[AVR32_INTC_INT3 - InterruptLevel]];
|
||||
}
|
||||
|
||||
/** Initializes the interrupt controller ready to handle interrupts. This must be called at the
|
||||
* start of the user program before any interrupts are registered or enabled.
|
||||
*/
|
||||
void INTC_Init(void)
|
||||
{
|
||||
for (uint8_t InterruptGroup = 0; InterruptGroup < AVR32_INTC_NUM_INT_GRPS; InterruptGroup++)
|
||||
{
|
||||
InterruptHandlers[InterruptGroup] = Unhandled_Interrupt;
|
||||
AVR32_INTC.ipr[InterruptGroup] = Autovector_Table[AVR32_INTC_INT0];
|
||||
}
|
||||
|
||||
__builtin_mtsr(AVR32_EVBA, (uintptr_t)&EVBA_Table);
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
#include "InterruptManagement.h"
|
||||
|
||||
/** Interrupt vector table, containing the ISR to call for each interrupt group */
|
||||
InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS];
|
||||
|
||||
/** ISR for unhandled interrupt groups */
|
||||
ISR(Unhandled_Interrupt)
|
||||
{
|
||||
for (;;);
|
||||
}
|
||||
|
||||
/** Retrieves the associated interrupt handler for the interrupt group currently being fired. This
|
||||
* is called directly from the exception handler routine before dispatching to the ISR.
|
||||
*/
|
||||
InterruptHandlerPtr_t INTC_GetInterruptHandler(const uint_reg_t InterruptLevel)
|
||||
{
|
||||
return InterruptHandlers[AVR32_INTC.icr[AVR32_INTC_INT3 - InterruptLevel]];
|
||||
}
|
||||
|
||||
/** Initializes the interrupt controller ready to handle interrupts. This must be called at the
|
||||
* start of the user program before any interrupts are registered or enabled.
|
||||
*/
|
||||
void INTC_Init(void)
|
||||
{
|
||||
for (uint8_t InterruptGroup = 0; InterruptGroup < AVR32_INTC_NUM_INT_GRPS; InterruptGroup++)
|
||||
{
|
||||
InterruptHandlers[InterruptGroup] = Unhandled_Interrupt;
|
||||
AVR32_INTC.ipr[InterruptGroup] = Autovector_Table[AVR32_INTC_INT0];
|
||||
}
|
||||
|
||||
__builtin_mtsr(AVR32_EVBA, (uintptr_t)&EVBA_Table);
|
||||
}
|
||||
|
||||
@@ -1,162 +1,162 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
|
||||
* handlers within the device.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PlatformDrivers
|
||||
* \defgroup Group_PlatformDrivers_UC3Interrupts UC3 Interrupt Controller Driver - LUFA/Platform/UC3/InterruptManagement.h
|
||||
* \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* \section Sec_Dependencies Module Source Dependencies
|
||||
* The following files must be built with any user project that uses this module:
|
||||
* - LUFA/Platform/UC3/InterruptManagement.c
|
||||
* - LUFA/Platform/UC3/Exception.S
|
||||
*
|
||||
* \section Sec_ModDescription Module Description
|
||||
* Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
|
||||
* handlers within the device.
|
||||
*
|
||||
* Usage Example:
|
||||
* \code
|
||||
* #include <LUFA/Platform/UC3/InterruptManagement.h>
|
||||
*
|
||||
* ISR(USB_Group_IRQ_Handler)
|
||||
* {
|
||||
* // USB group handler code here
|
||||
* }
|
||||
*
|
||||
* void main(void)
|
||||
* {
|
||||
* INTC_Init();
|
||||
* INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_USBB_IRQ), AVR32_INTC_INT0, USB_Group_IRQ_Handler);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _UC3_INTERRUPT_MANAGEMENT_H_
|
||||
#define _UC3_INTERRUPT_MANAGEMENT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Common/Common.h>
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Type Defines: */
|
||||
typedef void (*InterruptHandlerPtr_t)(void);
|
||||
|
||||
/* External Variables: */
|
||||
extern const void EVBA_Table;
|
||||
extern const uint32_t Autovector_Table[];
|
||||
extern InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS];
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Converts a given interrupt index into its assocated interrupt group.
|
||||
*
|
||||
* \param[in] IRQIndex Index of the interrupt request to convert.
|
||||
*
|
||||
* \return Interrupt group number associated with the interrupt index.
|
||||
*/
|
||||
#define INTC_IRQ_GROUP(IRQIndex) (IRQIndex / 32)
|
||||
|
||||
/** Converts a given interrupt index into its assocated interrupt line.
|
||||
*
|
||||
* \param[in] IRQIndex Index of the interrupt request to convert.
|
||||
*
|
||||
* \return Interrupt line number associated with the interrupt index.
|
||||
*/
|
||||
#define INTC_IRQ_LINE(IRQIndex) (IRQIndex % 32)
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Initializes the interrupt controller, nulling out all interrupt handlers ready for new registration. This
|
||||
* function should be called once on startup to ensure the interrupt controller is ready for use.
|
||||
*/
|
||||
void INTC_Init(void);
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Registers a handler for a given interrupt group. On the AVR32 UC3 devices, interrupts are grouped by
|
||||
* peripheral. To save on SRAM used, a single ISR handles all interrupt lines within a single group - to
|
||||
* determine the exact line that has interrupted within the group ISR handler, use \ref INTC_GetGroupInterrupts().
|
||||
*
|
||||
* If multiple interrupts with the same group are registered, the last registered handler will become the
|
||||
* handler called for interrupts raised within that group.
|
||||
*
|
||||
* To obtain the group number of a specific interrupt index, use the \ref INTC_IRQ_GROUP() macro.
|
||||
*
|
||||
* \param[in] GroupNumber Group number of the interrupt group to register a handler for.
|
||||
* \param[in] InterruptLevel Priority level for the specified interrupt, a \c AVR32_INTC_INT* mask.
|
||||
* \param[in] Handler Address of the ISR handler for the interrupt group.
|
||||
*/
|
||||
static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,
|
||||
const uint8_t InterruptLevel,
|
||||
const InterruptHandlerPtr_t Handler) ATTR_ALWAYS_INLINE;
|
||||
static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,
|
||||
const uint8_t InterruptLevel,
|
||||
const InterruptHandlerPtr_t Handler)
|
||||
{
|
||||
InterruptHandlers[GroupNumber] = Handler;
|
||||
AVR32_INTC.ipr[GroupNumber] = Autovector_Table[InterruptLevel];
|
||||
}
|
||||
|
||||
/** Retrieves the pending interrupts for a given interrupt group. The result of this function should be masked
|
||||
* against interrupt request indexes converted to a request line number via the \ref INTC_IRQ_LINE() macro. To
|
||||
* obtain the group number of a given interrupt request, use the \ref INTC_IRQ_GROUP() macro.
|
||||
*
|
||||
* \param[in] GroupNumber Group number of the interrupt group to check.
|
||||
*
|
||||
* \return Mask of pending interrupt lines for the given interrupt group.
|
||||
*/
|
||||
static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber) ATTR_ALWAYS_INLINE;
|
||||
static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber)
|
||||
{
|
||||
return AVR32_INTC.irr[GroupNumber];
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
|
||||
* handlers within the device.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PlatformDrivers
|
||||
* \defgroup Group_PlatformDrivers_UC3Interrupts UC3 Interrupt Controller Driver - LUFA/Platform/UC3/InterruptManagement.h
|
||||
* \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
|
||||
*
|
||||
* \section Sec_Dependencies Module Source Dependencies
|
||||
* The following files must be built with any user project that uses this module:
|
||||
* - LUFA/Platform/UC3/InterruptManagement.c
|
||||
* - LUFA/Platform/UC3/Exception.S
|
||||
*
|
||||
* \section Sec_ModDescription Module Description
|
||||
* Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
|
||||
* handlers within the device.
|
||||
*
|
||||
* Usage Example:
|
||||
* \code
|
||||
* #include <LUFA/Platform/UC3/InterruptManagement.h>
|
||||
*
|
||||
* ISR(USB_Group_IRQ_Handler)
|
||||
* {
|
||||
* // USB group handler code here
|
||||
* }
|
||||
*
|
||||
* void main(void)
|
||||
* {
|
||||
* INTC_Init();
|
||||
* INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_USBB_IRQ), AVR32_INTC_INT0, USB_Group_IRQ_Handler);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _UC3_INTERRUPT_MANAGEMENT_H_
|
||||
#define _UC3_INTERRUPT_MANAGEMENT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Common/Common.h>
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Type Defines: */
|
||||
typedef void (*InterruptHandlerPtr_t)(void);
|
||||
|
||||
/* External Variables: */
|
||||
extern const void EVBA_Table;
|
||||
extern const uint32_t Autovector_Table[];
|
||||
extern InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS];
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Converts a given interrupt index into its assocated interrupt group.
|
||||
*
|
||||
* \param[in] IRQIndex Index of the interrupt request to convert.
|
||||
*
|
||||
* \return Interrupt group number associated with the interrupt index.
|
||||
*/
|
||||
#define INTC_IRQ_GROUP(IRQIndex) (IRQIndex / 32)
|
||||
|
||||
/** Converts a given interrupt index into its assocated interrupt line.
|
||||
*
|
||||
* \param[in] IRQIndex Index of the interrupt request to convert.
|
||||
*
|
||||
* \return Interrupt line number associated with the interrupt index.
|
||||
*/
|
||||
#define INTC_IRQ_LINE(IRQIndex) (IRQIndex % 32)
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Initializes the interrupt controller, nulling out all interrupt handlers ready for new registration. This
|
||||
* function should be called once on startup to ensure the interrupt controller is ready for use.
|
||||
*/
|
||||
void INTC_Init(void);
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Registers a handler for a given interrupt group. On the AVR32 UC3 devices, interrupts are grouped by
|
||||
* peripheral. To save on SRAM used, a single ISR handles all interrupt lines within a single group - to
|
||||
* determine the exact line that has interrupted within the group ISR handler, use \ref INTC_GetGroupInterrupts().
|
||||
*
|
||||
* If multiple interrupts with the same group are registered, the last registered handler will become the
|
||||
* handler called for interrupts raised within that group.
|
||||
*
|
||||
* To obtain the group number of a specific interrupt index, use the \ref INTC_IRQ_GROUP() macro.
|
||||
*
|
||||
* \param[in] GroupNumber Group number of the interrupt group to register a handler for.
|
||||
* \param[in] InterruptLevel Priority level for the specified interrupt, a \c AVR32_INTC_INT* mask.
|
||||
* \param[in] Handler Address of the ISR handler for the interrupt group.
|
||||
*/
|
||||
static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,
|
||||
const uint8_t InterruptLevel,
|
||||
const InterruptHandlerPtr_t Handler) ATTR_ALWAYS_INLINE;
|
||||
static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,
|
||||
const uint8_t InterruptLevel,
|
||||
const InterruptHandlerPtr_t Handler)
|
||||
{
|
||||
InterruptHandlers[GroupNumber] = Handler;
|
||||
AVR32_INTC.ipr[GroupNumber] = Autovector_Table[InterruptLevel];
|
||||
}
|
||||
|
||||
/** Retrieves the pending interrupts for a given interrupt group. The result of this function should be masked
|
||||
* against interrupt request indexes converted to a request line number via the \ref INTC_IRQ_LINE() macro. To
|
||||
* obtain the group number of a given interrupt request, use the \ref INTC_IRQ_GROUP() macro.
|
||||
*
|
||||
* \param[in] GroupNumber Group number of the interrupt group to check.
|
||||
*
|
||||
* \return Mask of pending interrupt lines for the given interrupt group.
|
||||
*/
|
||||
static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber) ATTR_ALWAYS_INLINE;
|
||||
static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber)
|
||||
{
|
||||
return AVR32_INTC.irr[GroupNumber];
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,298 +1,298 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Module Clock Driver for the AVR USB XMEGA microcontrollers.
|
||||
*
|
||||
* Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration
|
||||
* of the various clocks within the device to clock the various peripherals.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PlatformDrivers
|
||||
* \defgroup Group_PlatformDrivers_XMEGAClocks AVR USB XMEGA Clock Management Driver - LUFA/Platform/XMEGA/ClockManagement.h
|
||||
* \brief Module Clock Driver for the AVR USB XMEGA microcontrollers.
|
||||
*
|
||||
* \section Sec_Dependencies Module Source Dependencies
|
||||
* The following files must be built with any user project that uses this module:
|
||||
* - None
|
||||
*
|
||||
* \section Sec_ModDescription Module Description
|
||||
* Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration
|
||||
* of the various clocks within the device to clock the various peripherals.
|
||||
*
|
||||
* Usage Example:
|
||||
* \code
|
||||
* #include <LUFA/Platform/XMEGA/ClockManagement.h>
|
||||
*
|
||||
* void main(void)
|
||||
* {
|
||||
* // Start the internal 32MHz RC oscillator and switch the CPU core to run from it
|
||||
* AVR32CLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
|
||||
* XMEGACLK_SetCPUClockSource(CLOCK_SRC_INT_RC32MHZ, F_CPU);
|
||||
*
|
||||
* // Start the external oscillator and multiply up the frequency
|
||||
* AVR32CLK_StartExternalOscillator(EXOSC_FREQ_9MHZ_MAX, EXOSC_START_1KCLK);
|
||||
* AVR32CLK_StartPLL(CLOCK_SRC_XOSC, 8000000, F_USB);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _XMEGA_CLOCK_MANAGEMENT_H_
|
||||
#define _XMEGA_CLOCK_MANAGEMENT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Common/Common.h>
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Enum for the possible external oscillator frequency ranges. */
|
||||
enum XMEGA_Extern_OSC_ClockFrequency_t
|
||||
{
|
||||
EXOSC_FREQ_2MHZ_MAX = OSC_FRQRANGE_04TO2_gc, /**< External crystal oscillator equal to or slower than 2MHz. */
|
||||
EXOSC_FREQ_9MHZ_MAX = OSC_FRQRANGE_2TO9_gc, /**< External crystal oscillator equal to or slower than 9MHz. */
|
||||
EXOSC_FREQ_12MHZ_MAX = OSC_FRQRANGE_9TO12_gc, /**< External crystal oscillator equal to or slower than 12MHz. */
|
||||
EXOSC_FREQ_16MHZ_MAX = OSC_FRQRANGE_12TO16_gc, /**< External crystal oscillator equal to or slower than 16MHz. */
|
||||
};
|
||||
|
||||
/** Enum for the possible external oscillator statup times. */
|
||||
enum XMEGA_Extern_OSC_ClockStartup_t
|
||||
{
|
||||
EXOSC_START_6CLK = OSC_XOSCSEL_EXTCLK_gc, /**< Wait 6 clock cycles before startup (external clock). */
|
||||
EXOSC_START_32KCLK = OSC_XOSCSEL_32KHz_gc, /**< Wait 32K clock cycles before startup (32.768KHz crystal). */
|
||||
EXOSC_START_256CLK = OSC_XOSCSEL_XTAL_256CLK_gc, /**< Wait 256 clock cycles before startup. */
|
||||
EXOSC_START_1KCLK = OSC_XOSCSEL_XTAL_1KCLK_gc, /**< Wait 1K clock cycles before startup. */
|
||||
EXOSC_START_16KCLK = OSC_XOSCSEL_XTAL_16KCLK_gc, /**< Wait 16K clock cycles before startup. */
|
||||
};
|
||||
|
||||
/** Enum for the possible module clock sources. */
|
||||
enum XMEGA_System_ClockSource_t
|
||||
{
|
||||
CLOCK_SRC_INT_RC2MHZ = 0, /**< Clock sourced from the Internal 2MHz RC Oscillator clock. */
|
||||
CLOCK_SRC_INT_RC32MHZ = 1, /**< Clock sourced from the Internal 32MHz RC Oscillator clock. */
|
||||
CLOCK_SRC_INT_RC32KHZ = 2, /**< Clock sourced from the Internal 32KHz RC Oscillator clock. */
|
||||
CLOCK_SRC_XOSC = 3, /**< Clock sourced from the External Oscillator clock. */
|
||||
CLOCK_SRC_PLL = 4, /**< Clock sourced from the Internal PLL clock. */
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Starts the external oscillator of the XMEGA microcontroller, with the given options. This routine blocks until
|
||||
* the oscillator is ready for use.
|
||||
*
|
||||
* \param[in] FreqRange Frequency range of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockFrequency_t.
|
||||
* \param[in] Startup Statup time of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockStartup_t.
|
||||
*
|
||||
* \return Boolean \c true if the external oscillator was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t FreqRange,
|
||||
const uint8_t Startup) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t FreqRange,
|
||||
const uint8_t Startup)
|
||||
{
|
||||
OSC.XOSCCTRL = (FreqRange | ((Startup == EXOSC_START_32KCLK) ? OSC_X32KLPM_bm : 0) | Startup);
|
||||
OSC.CTRL |= OSC_XOSCEN_bm;
|
||||
|
||||
while (!(OSC.STATUS & OSC_XOSCRDY_bm));
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the external oscillator of the XMEGA microcontroller. */
|
||||
static inline void AVR32CLK_StopExternalOscillator(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopExternalOscillator(void)
|
||||
{
|
||||
OSC.CTRL &= ~OSC_XOSCEN_bm;
|
||||
}
|
||||
|
||||
/** Starts the given internal oscillator of the XMEGA microcontroller, with the given options. This routine blocks until
|
||||
* the oscillator is ready for use.
|
||||
*
|
||||
* \param[in] Source Internal oscillator to start, a value from \ref XMEGA_System_ClockSource_t.
|
||||
*
|
||||
* \return Boolean \c true if the internal oscillator was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline uint8_t AVR32CLK_StartInternalOscillator(const uint8_t Source) ATTR_ALWAYS_INLINE;
|
||||
static inline uint8_t AVR32CLK_StartInternalOscillator(const uint8_t Source)
|
||||
{
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_INT_RC2MHZ:
|
||||
OSC.CTRL |= OSC_RC2MEN_bm;
|
||||
while (!(OSC.STATUS & OSC_RC2MRDY_bm));
|
||||
return true;
|
||||
case CLOCK_SRC_INT_RC32MHZ:
|
||||
OSC.CTRL |= OSC_RC32MEN_bm;
|
||||
while (!(OSC.STATUS & OSC_RC32MRDY_bm));
|
||||
return true;
|
||||
case CLOCK_SRC_INT_RC32KHZ:
|
||||
OSC.CTRL |= OSC_RC32KEN_bm;
|
||||
while (!(OSC.STATUS & OSC_RC32KRDY_bm));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Stops the given internal oscillator of the XMEGA microcontroller.
|
||||
*
|
||||
* \param[in] Source Internal oscillator to stop, a value from \ref XMEGA_System_ClockSource_t.
|
||||
*
|
||||
* \return Boolean \c true if the internal oscillator was successfully stopped, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StopInternalOscillator(const uint8_t Source) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StopInternalOscillator(const uint8_t Source)
|
||||
{
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_INT_RC2MHZ:
|
||||
OSC.CTRL &= ~OSC_RC2MEN_bm;
|
||||
return true;
|
||||
case CLOCK_SRC_INT_RC32MHZ:
|
||||
OSC.CTRL &= ~OSC_RC32MEN_bm;
|
||||
return true;
|
||||
case CLOCK_SRC_INT_RC32KHZ:
|
||||
OSC.CTRL &= ~OSC_RC32KEN_bm;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Starts the PLL of the XMEGA microcontroller, with the given options. This routine blocks until the PLL is ready for use.
|
||||
*
|
||||
* \note The output frequency must be equal to or greater than the source frequency.
|
||||
*
|
||||
* \param[in] Source Clock source for the PLL, a value from \ref XMEGA_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the PLL's clock source, in Hz.
|
||||
* \param[in] Frequency Target frequency of the PLL's output.
|
||||
*
|
||||
* \return Boolean \c true if the PLL was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartPLL(const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartPLL(const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency)
|
||||
{
|
||||
uint8_t MulFactor = (Frequency / SourceFreq);
|
||||
|
||||
if (SourceFreq > Frequency)
|
||||
return false;
|
||||
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_INT_RC2MHZ:
|
||||
OSC.PLLCTRL = (OSC_PLLSRC_RC2M_gc | MulFactor);
|
||||
break;
|
||||
case CLOCK_SRC_INT_RC32MHZ:
|
||||
OSC.PLLCTRL = (OSC_PLLSRC_RC32M_gc | MulFactor);
|
||||
break;
|
||||
case CLOCK_SRC_XOSC:
|
||||
OSC.PLLCTRL = (OSC_PLLSRC_XOSC_gc | MulFactor);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
OSC.CTRL |= OSC_PLLEN_bm;
|
||||
|
||||
while (!(OSC.STATUS & OSC_PLLRDY_bm));
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the PLL of the XMEGA microcontroller. */
|
||||
static inline void AVR32CLK_StopPLL(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopPLL(void)
|
||||
{
|
||||
OSC.CTRL &= ~OSC_PLLEN_bm;
|
||||
}
|
||||
|
||||
/** Sets the clock source for the main microcontroller core. The given clock source should be configured
|
||||
* and ready for use before this function is called.
|
||||
*
|
||||
* \param[in] Source Clock source for the CPU core, a value from \ref XMEGA_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the CPU core's clock source, in Hz.
|
||||
*
|
||||
* \return Boolean \c true if the CPU core clock was sucessfully altered, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool XMEGACLK_SetCPUClockSource(const uint8_t Source,
|
||||
const uint32_t SourceFreq) ATTR_ALWAYS_INLINE;
|
||||
static inline bool XMEGACLK_SetCPUClockSource(const uint8_t Source,
|
||||
const uint32_t SourceFreq)
|
||||
{
|
||||
uint8_t ClockSourceMask = 0;
|
||||
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_INT_RC2MHZ:
|
||||
ClockSourceMask = CLK_SCLKSEL_RC2M_gc;
|
||||
break;
|
||||
case CLOCK_SRC_INT_RC32MHZ:
|
||||
ClockSourceMask = CLK_SCLKSEL_RC32M_gc;
|
||||
break;
|
||||
case CLOCK_SRC_INT_RC32KHZ:
|
||||
ClockSourceMask = CLK_SCLKSEL_RC32K_gc;
|
||||
break;
|
||||
case CLOCK_SRC_XOSC:
|
||||
ClockSourceMask = CLK_SCLKSEL_XOSC_gc;
|
||||
break;
|
||||
case CLOCK_SRC_PLL:
|
||||
ClockSourceMask = CLK_SCLKSEL_PLL_gc;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
CCP = CCP_IOREG_gc;
|
||||
CLK.CTRL = ClockSourceMask;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
|
||||
Delay_MS(1);
|
||||
return (CLK.CTRL == ClockSourceMask);
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Module Clock Driver for the AVR USB XMEGA microcontrollers.
|
||||
*
|
||||
* Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration
|
||||
* of the various clocks within the device to clock the various peripherals.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PlatformDrivers
|
||||
* \defgroup Group_PlatformDrivers_XMEGAClocks AVR USB XMEGA Clock Management Driver - LUFA/Platform/XMEGA/ClockManagement.h
|
||||
* \brief Module Clock Driver for the AVR USB XMEGA microcontrollers.
|
||||
*
|
||||
* \section Sec_Dependencies Module Source Dependencies
|
||||
* The following files must be built with any user project that uses this module:
|
||||
* - None
|
||||
*
|
||||
* \section Sec_ModDescription Module Description
|
||||
* Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration
|
||||
* of the various clocks within the device to clock the various peripherals.
|
||||
*
|
||||
* Usage Example:
|
||||
* \code
|
||||
* #include <LUFA/Platform/XMEGA/ClockManagement.h>
|
||||
*
|
||||
* void main(void)
|
||||
* {
|
||||
* // Start the internal 32MHz RC oscillator and switch the CPU core to run from it
|
||||
* AVR32CLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
|
||||
* XMEGACLK_SetCPUClockSource(CLOCK_SRC_INT_RC32MHZ, F_CPU);
|
||||
*
|
||||
* // Start the external oscillator and multiply up the frequency
|
||||
* AVR32CLK_StartExternalOscillator(EXOSC_FREQ_9MHZ_MAX, EXOSC_START_1KCLK);
|
||||
* AVR32CLK_StartPLL(CLOCK_SRC_XOSC, 8000000, F_USB);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _XMEGA_CLOCK_MANAGEMENT_H_
|
||||
#define _XMEGA_CLOCK_MANAGEMENT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Common/Common.h>
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Enum for the possible external oscillator frequency ranges. */
|
||||
enum XMEGA_Extern_OSC_ClockFrequency_t
|
||||
{
|
||||
EXOSC_FREQ_2MHZ_MAX = OSC_FRQRANGE_04TO2_gc, /**< External crystal oscillator equal to or slower than 2MHz. */
|
||||
EXOSC_FREQ_9MHZ_MAX = OSC_FRQRANGE_2TO9_gc, /**< External crystal oscillator equal to or slower than 9MHz. */
|
||||
EXOSC_FREQ_12MHZ_MAX = OSC_FRQRANGE_9TO12_gc, /**< External crystal oscillator equal to or slower than 12MHz. */
|
||||
EXOSC_FREQ_16MHZ_MAX = OSC_FRQRANGE_12TO16_gc, /**< External crystal oscillator equal to or slower than 16MHz. */
|
||||
};
|
||||
|
||||
/** Enum for the possible external oscillator statup times. */
|
||||
enum XMEGA_Extern_OSC_ClockStartup_t
|
||||
{
|
||||
EXOSC_START_6CLK = OSC_XOSCSEL_EXTCLK_gc, /**< Wait 6 clock cycles before startup (external clock). */
|
||||
EXOSC_START_32KCLK = OSC_XOSCSEL_32KHz_gc, /**< Wait 32K clock cycles before startup (32.768KHz crystal). */
|
||||
EXOSC_START_256CLK = OSC_XOSCSEL_XTAL_256CLK_gc, /**< Wait 256 clock cycles before startup. */
|
||||
EXOSC_START_1KCLK = OSC_XOSCSEL_XTAL_1KCLK_gc, /**< Wait 1K clock cycles before startup. */
|
||||
EXOSC_START_16KCLK = OSC_XOSCSEL_XTAL_16KCLK_gc, /**< Wait 16K clock cycles before startup. */
|
||||
};
|
||||
|
||||
/** Enum for the possible module clock sources. */
|
||||
enum XMEGA_System_ClockSource_t
|
||||
{
|
||||
CLOCK_SRC_INT_RC2MHZ = 0, /**< Clock sourced from the Internal 2MHz RC Oscillator clock. */
|
||||
CLOCK_SRC_INT_RC32MHZ = 1, /**< Clock sourced from the Internal 32MHz RC Oscillator clock. */
|
||||
CLOCK_SRC_INT_RC32KHZ = 2, /**< Clock sourced from the Internal 32KHz RC Oscillator clock. */
|
||||
CLOCK_SRC_XOSC = 3, /**< Clock sourced from the External Oscillator clock. */
|
||||
CLOCK_SRC_PLL = 4, /**< Clock sourced from the Internal PLL clock. */
|
||||
};
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Starts the external oscillator of the XMEGA microcontroller, with the given options. This routine blocks until
|
||||
* the oscillator is ready for use.
|
||||
*
|
||||
* \param[in] FreqRange Frequency range of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockFrequency_t.
|
||||
* \param[in] Startup Statup time of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockStartup_t.
|
||||
*
|
||||
* \return Boolean \c true if the external oscillator was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t FreqRange,
|
||||
const uint8_t Startup) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t FreqRange,
|
||||
const uint8_t Startup)
|
||||
{
|
||||
OSC.XOSCCTRL = (FreqRange | ((Startup == EXOSC_START_32KCLK) ? OSC_X32KLPM_bm : 0) | Startup);
|
||||
OSC.CTRL |= OSC_XOSCEN_bm;
|
||||
|
||||
while (!(OSC.STATUS & OSC_XOSCRDY_bm));
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the external oscillator of the XMEGA microcontroller. */
|
||||
static inline void AVR32CLK_StopExternalOscillator(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopExternalOscillator(void)
|
||||
{
|
||||
OSC.CTRL &= ~OSC_XOSCEN_bm;
|
||||
}
|
||||
|
||||
/** Starts the given internal oscillator of the XMEGA microcontroller, with the given options. This routine blocks until
|
||||
* the oscillator is ready for use.
|
||||
*
|
||||
* \param[in] Source Internal oscillator to start, a value from \ref XMEGA_System_ClockSource_t.
|
||||
*
|
||||
* \return Boolean \c true if the internal oscillator was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline uint8_t AVR32CLK_StartInternalOscillator(const uint8_t Source) ATTR_ALWAYS_INLINE;
|
||||
static inline uint8_t AVR32CLK_StartInternalOscillator(const uint8_t Source)
|
||||
{
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_INT_RC2MHZ:
|
||||
OSC.CTRL |= OSC_RC2MEN_bm;
|
||||
while (!(OSC.STATUS & OSC_RC2MRDY_bm));
|
||||
return true;
|
||||
case CLOCK_SRC_INT_RC32MHZ:
|
||||
OSC.CTRL |= OSC_RC32MEN_bm;
|
||||
while (!(OSC.STATUS & OSC_RC32MRDY_bm));
|
||||
return true;
|
||||
case CLOCK_SRC_INT_RC32KHZ:
|
||||
OSC.CTRL |= OSC_RC32KEN_bm;
|
||||
while (!(OSC.STATUS & OSC_RC32KRDY_bm));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Stops the given internal oscillator of the XMEGA microcontroller.
|
||||
*
|
||||
* \param[in] Source Internal oscillator to stop, a value from \ref XMEGA_System_ClockSource_t.
|
||||
*
|
||||
* \return Boolean \c true if the internal oscillator was successfully stopped, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StopInternalOscillator(const uint8_t Source) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StopInternalOscillator(const uint8_t Source)
|
||||
{
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_INT_RC2MHZ:
|
||||
OSC.CTRL &= ~OSC_RC2MEN_bm;
|
||||
return true;
|
||||
case CLOCK_SRC_INT_RC32MHZ:
|
||||
OSC.CTRL &= ~OSC_RC32MEN_bm;
|
||||
return true;
|
||||
case CLOCK_SRC_INT_RC32KHZ:
|
||||
OSC.CTRL &= ~OSC_RC32KEN_bm;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Starts the PLL of the XMEGA microcontroller, with the given options. This routine blocks until the PLL is ready for use.
|
||||
*
|
||||
* \note The output frequency must be equal to or greater than the source frequency.
|
||||
*
|
||||
* \param[in] Source Clock source for the PLL, a value from \ref XMEGA_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the PLL's clock source, in Hz.
|
||||
* \param[in] Frequency Target frequency of the PLL's output.
|
||||
*
|
||||
* \return Boolean \c true if the PLL was successfully started, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool AVR32CLK_StartPLL(const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency) ATTR_ALWAYS_INLINE;
|
||||
static inline bool AVR32CLK_StartPLL(const uint8_t Source,
|
||||
const uint32_t SourceFreq,
|
||||
const uint32_t Frequency)
|
||||
{
|
||||
uint8_t MulFactor = (Frequency / SourceFreq);
|
||||
|
||||
if (SourceFreq > Frequency)
|
||||
return false;
|
||||
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_INT_RC2MHZ:
|
||||
OSC.PLLCTRL = (OSC_PLLSRC_RC2M_gc | MulFactor);
|
||||
break;
|
||||
case CLOCK_SRC_INT_RC32MHZ:
|
||||
OSC.PLLCTRL = (OSC_PLLSRC_RC32M_gc | MulFactor);
|
||||
break;
|
||||
case CLOCK_SRC_XOSC:
|
||||
OSC.PLLCTRL = (OSC_PLLSRC_XOSC_gc | MulFactor);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
OSC.CTRL |= OSC_PLLEN_bm;
|
||||
|
||||
while (!(OSC.STATUS & OSC_PLLRDY_bm));
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Stops the PLL of the XMEGA microcontroller. */
|
||||
static inline void AVR32CLK_StopPLL(void) ATTR_ALWAYS_INLINE;
|
||||
static inline void AVR32CLK_StopPLL(void)
|
||||
{
|
||||
OSC.CTRL &= ~OSC_PLLEN_bm;
|
||||
}
|
||||
|
||||
/** Sets the clock source for the main microcontroller core. The given clock source should be configured
|
||||
* and ready for use before this function is called.
|
||||
*
|
||||
* \param[in] Source Clock source for the CPU core, a value from \ref XMEGA_System_ClockSource_t.
|
||||
* \param[in] SourceFreq Frequency of the CPU core's clock source, in Hz.
|
||||
*
|
||||
* \return Boolean \c true if the CPU core clock was sucessfully altered, \c false if invalid parameters specified.
|
||||
*/
|
||||
static inline bool XMEGACLK_SetCPUClockSource(const uint8_t Source,
|
||||
const uint32_t SourceFreq) ATTR_ALWAYS_INLINE;
|
||||
static inline bool XMEGACLK_SetCPUClockSource(const uint8_t Source,
|
||||
const uint32_t SourceFreq)
|
||||
{
|
||||
uint8_t ClockSourceMask = 0;
|
||||
|
||||
switch (Source)
|
||||
{
|
||||
case CLOCK_SRC_INT_RC2MHZ:
|
||||
ClockSourceMask = CLK_SCLKSEL_RC2M_gc;
|
||||
break;
|
||||
case CLOCK_SRC_INT_RC32MHZ:
|
||||
ClockSourceMask = CLK_SCLKSEL_RC32M_gc;
|
||||
break;
|
||||
case CLOCK_SRC_INT_RC32KHZ:
|
||||
ClockSourceMask = CLK_SCLKSEL_RC32K_gc;
|
||||
break;
|
||||
case CLOCK_SRC_XOSC:
|
||||
ClockSourceMask = CLK_SCLKSEL_XOSC_gc;
|
||||
break;
|
||||
case CLOCK_SRC_PLL:
|
||||
ClockSourceMask = CLK_SCLKSEL_PLL_gc;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
|
||||
GlobalInterruptDisable();
|
||||
|
||||
CCP = CCP_IOREG_gc;
|
||||
CLK.CTRL = ClockSourceMask;
|
||||
|
||||
SetGlobalInterruptMask(CurrentGlobalInt);
|
||||
|
||||
Delay_MS(1);
|
||||
return (CLK.CTRL == ClockSourceMask);
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,320 +1,320 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the HIDReportViewer project. This file contains the main tasks of
|
||||
* the project and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "HIDReportViewer.h"
|
||||
|
||||
/** Processed HID report descriptor items structure, containing information on each HID report element */
|
||||
static HID_ReportInfo_t HIDReportInfo;
|
||||
|
||||
/** 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_Host_t Device_HID_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.DataINPipeNumber = 1,
|
||||
.DataINPipeDoubleBank = false,
|
||||
|
||||
.DataOUTPipeNumber = 2,
|
||||
.DataOUTPipeDoubleBank = false,
|
||||
|
||||
.HIDInterfaceProtocol = HID_CSCP_NonBootProtocol,
|
||||
|
||||
.HIDParserData = &HIDReportInfo
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** Main program entry point. This routine configures the hardware required by the application, then
|
||||
* enters a loop to run the application tasks in sequence.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
SetupHardware();
|
||||
|
||||
puts_P(PSTR(ESC_FG_CYAN "HID Device Report Viewer Running.\r\n" ESC_FG_WHITE));
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
RetrieveDeviceData();
|
||||
|
||||
HID_Host_USBTask(&Device_HID_Interface);
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Task to retrieve the HID device information from an attached device, and output
|
||||
* the relevant data to the serial port for analysis.
|
||||
*/
|
||||
void RetrieveDeviceData(void)
|
||||
{
|
||||
if (USB_CurrentMode != USB_MODE_Host)
|
||||
return;
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||||
|
||||
OutputReportSizes();
|
||||
OutputParsedReportItems();
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
USB_Host_SetDeviceConfiguration(0);
|
||||
}
|
||||
|
||||
/** Prints a summary of the device's HID report sizes from the HID parser output to the serial port
|
||||
* for display to the user.
|
||||
*/
|
||||
void OutputReportSizes(void)
|
||||
{
|
||||
printf_P(PSTR("\r\n\r\nTotal Device Reports: %" PRId8 "\r\n"), HIDReportInfo.TotalDeviceReports);
|
||||
|
||||
for (uint8_t ReportIndex = 0; ReportIndex < HIDReportInfo.TotalDeviceReports; ReportIndex++)
|
||||
{
|
||||
const HID_ReportSizeInfo_t* CurrReportIDInfo = &HIDReportInfo.ReportIDSizes[ReportIndex];
|
||||
|
||||
uint8_t ReportSizeInBits = CurrReportIDInfo->ReportSizeBits[HID_REPORT_ITEM_In];
|
||||
uint8_t ReportSizeOutBits = CurrReportIDInfo->ReportSizeBits[HID_REPORT_ITEM_Out];
|
||||
uint8_t ReportSizeFeatureBits = CurrReportIDInfo->ReportSizeBits[HID_REPORT_ITEM_Feature];
|
||||
|
||||
/* Print out the byte sizes of each report within the device */
|
||||
printf_P(PSTR(" + Report ID 0x%02" PRIX8 "\r\n"
|
||||
" - Input Data: %" PRId8 " bits (%" PRId8 " bytes)\r\n"
|
||||
" - Output Data: %" PRId8 " bits (%" PRId8 " bytes)\r\n"
|
||||
" - Feature Data: %" PRId8 " bits (%" PRId8 " bytes)\r\n"),
|
||||
CurrReportIDInfo->ReportID,
|
||||
ReportSizeInBits,
|
||||
((ReportSizeInBits >> 3) + ((ReportSizeInBits & 0x07) != 0)),
|
||||
ReportSizeOutBits,
|
||||
((ReportSizeOutBits >> 3) + ((ReportSizeOutBits & 0x07) != 0)),
|
||||
ReportSizeFeatureBits,
|
||||
((ReportSizeFeatureBits >> 3) + ((ReportSizeFeatureBits & 0x07) != 0)));
|
||||
}
|
||||
}
|
||||
|
||||
/** Prints a summary of the device's parsed and stored report items along with their attributes
|
||||
* to the serial port for display to the user.
|
||||
*/
|
||||
void OutputParsedReportItems(void)
|
||||
{
|
||||
printf_P(PSTR("\r\nReport Items (%" PRId8 " in Table):\r\n"), HIDReportInfo.TotalReportItems);
|
||||
|
||||
for (uint8_t ItemIndex = 0; ItemIndex < HIDReportInfo.TotalReportItems; ItemIndex++)
|
||||
{
|
||||
const HID_ReportItem_t* RItem = &HIDReportInfo.ReportItems[ItemIndex];
|
||||
|
||||
printf_P(PSTR(" + Item %" PRId8 ":\r\n"
|
||||
" - Report ID: 0x%02" PRIX8 "\r\n"
|
||||
" - Data Direction: %s\r\n"
|
||||
" - Item Flags: 0x%02" PRIX8 "\r\n"
|
||||
" - Item Offset (Bits): 0x%02" PRIX8 "\r\n"
|
||||
" - Item Size (Bits): 0x%02" PRIX8 "\r\n"
|
||||
" - Usage Page: 0x%04" PRIX16 "\r\n"
|
||||
" - Usage: 0x%04" PRIX16 "\r\n"
|
||||
" - Unit Type: 0x%08" PRIX32 "\r\n"
|
||||
" - Unit Exponent: 0x%02" PRIX8 "\r\n"
|
||||
" - Logical Minimum: 0x%08" PRIX32 "\r\n"
|
||||
" - Logical Maximum: 0x%08" PRIX32 "\r\n"
|
||||
" - Physical Minimum: 0x%08" PRIX32 "\r\n"
|
||||
" - Physical Maximum: 0x%08" PRIX32 "\r\n"
|
||||
" - Collection Path:\r\n"),
|
||||
ItemIndex,
|
||||
RItem->ReportID,
|
||||
((RItem->ItemType == HID_REPORT_ITEM_In) ? "IN" : ((RItem->ItemType == HID_REPORT_ITEM_Out) ? "OUT" : "FEATURE")),
|
||||
RItem->ItemFlags,
|
||||
RItem->BitOffset,
|
||||
RItem->Attributes.BitSize,
|
||||
RItem->Attributes.Usage.Page,
|
||||
RItem->Attributes.Usage.Usage,
|
||||
RItem->Attributes.Unit.Type,
|
||||
RItem->Attributes.Unit.Exponent,
|
||||
RItem->Attributes.Logical.Minimum,
|
||||
RItem->Attributes.Logical.Maximum,
|
||||
RItem->Attributes.Physical.Minimum,
|
||||
RItem->Attributes.Physical.Maximum);
|
||||
|
||||
OutputCollectionPath(RItem->CollectionPath);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prints the HID Collection path (along with each node's attributes) to the serial port
|
||||
* for display to the user, from the given starting node to the root node.
|
||||
*
|
||||
* \param[in] CollectionPath Starting HID Collection node to print
|
||||
*/
|
||||
void OutputCollectionPath(const HID_CollectionPath_t* const CollectionPath)
|
||||
{
|
||||
const HID_CollectionPath_t* CurrentNode = CollectionPath;
|
||||
|
||||
while (CurrentNode != NULL)
|
||||
{
|
||||
printf_P(PSTR(" |\r\n"
|
||||
" - Type: 0x%02" PRIX8 "\r\n"
|
||||
" - Usage: 0x%02" PRIX8 "\r\n"),
|
||||
CurrentNode->Type, CurrentNode->Usage);
|
||||
|
||||
CurrentNode = CurrentNode->Parent;
|
||||
}
|
||||
|
||||
printf_P(PSTR(" |\r\n"
|
||||
" END\r\n"));
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
Serial_Init(9600, false);
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Create a stdio stream for the serial port for stdin and stdout */
|
||||
Serial_CreateStream(NULL);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
|
||||
* starts the library USB task to begin the enumeration and USB management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceAttached(void)
|
||||
{
|
||||
puts_P(PSTR("Device Attached.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and
|
||||
* stops the library USB task management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceUnattached(void)
|
||||
{
|
||||
puts_P(PSTR("\r\nDevice Unattached.\r\n"));
|
||||
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);
|
||||
|
||||
uint16_t ConfigDescriptorSize;
|
||||
uint8_t ConfigDescriptorData[512];
|
||||
|
||||
if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
|
||||
sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
|
||||
{
|
||||
puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (HID_Host_ConfigurePipes(&Device_HID_Interface,
|
||||
ConfigDescriptorSize, ConfigDescriptorData) != HID_ENUMERROR_NoError)
|
||||
{
|
||||
puts_P(PSTR("Attached Device Not a Valid HID Device.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
puts_P(PSTR("Error Setting Device Configuration.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (HID_Host_SetReportProtocol(&Device_HID_Interface) != 0)
|
||||
{
|
||||
puts_P(PSTR("Error Setting Report Protocol Mode.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
USB_Host_SetDeviceConfiguration(0);
|
||||
return;
|
||||
}
|
||||
|
||||
puts_P(PSTR("HID Device Enumerated.\r\n"));
|
||||
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();
|
||||
|
||||
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
|
||||
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while
|
||||
* enumerating an attached USB device.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
|
||||
const uint8_t SubErrorCode)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
|
||||
" -- Error Code %d\r\n"
|
||||
" -- Sub Error Code %d\r\n"
|
||||
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store
|
||||
* an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items
|
||||
* we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would
|
||||
* have occupied).
|
||||
*
|
||||
* \param[in] CurrentItem Pointer to the item the HID report parser is currently working with
|
||||
*
|
||||
* \return Boolean true if the item should be stored into the HID report structure, false if it should be discarded
|
||||
*/
|
||||
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the HIDReportViewer project. This file contains the main tasks of
|
||||
* the project and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "HIDReportViewer.h"
|
||||
|
||||
/** Processed HID report descriptor items structure, containing information on each HID report element */
|
||||
static HID_ReportInfo_t HIDReportInfo;
|
||||
|
||||
/** 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_Host_t Device_HID_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.DataINPipeNumber = 1,
|
||||
.DataINPipeDoubleBank = false,
|
||||
|
||||
.DataOUTPipeNumber = 2,
|
||||
.DataOUTPipeDoubleBank = false,
|
||||
|
||||
.HIDInterfaceProtocol = HID_CSCP_NonBootProtocol,
|
||||
|
||||
.HIDParserData = &HIDReportInfo
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** Main program entry point. This routine configures the hardware required by the application, then
|
||||
* enters a loop to run the application tasks in sequence.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
SetupHardware();
|
||||
|
||||
puts_P(PSTR(ESC_FG_CYAN "HID Device Report Viewer Running.\r\n" ESC_FG_WHITE));
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
RetrieveDeviceData();
|
||||
|
||||
HID_Host_USBTask(&Device_HID_Interface);
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Task to retrieve the HID device information from an attached device, and output
|
||||
* the relevant data to the serial port for analysis.
|
||||
*/
|
||||
void RetrieveDeviceData(void)
|
||||
{
|
||||
if (USB_CurrentMode != USB_MODE_Host)
|
||||
return;
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||||
|
||||
OutputReportSizes();
|
||||
OutputParsedReportItems();
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
USB_Host_SetDeviceConfiguration(0);
|
||||
}
|
||||
|
||||
/** Prints a summary of the device's HID report sizes from the HID parser output to the serial port
|
||||
* for display to the user.
|
||||
*/
|
||||
void OutputReportSizes(void)
|
||||
{
|
||||
printf_P(PSTR("\r\n\r\nTotal Device Reports: %" PRId8 "\r\n"), HIDReportInfo.TotalDeviceReports);
|
||||
|
||||
for (uint8_t ReportIndex = 0; ReportIndex < HIDReportInfo.TotalDeviceReports; ReportIndex++)
|
||||
{
|
||||
const HID_ReportSizeInfo_t* CurrReportIDInfo = &HIDReportInfo.ReportIDSizes[ReportIndex];
|
||||
|
||||
uint8_t ReportSizeInBits = CurrReportIDInfo->ReportSizeBits[HID_REPORT_ITEM_In];
|
||||
uint8_t ReportSizeOutBits = CurrReportIDInfo->ReportSizeBits[HID_REPORT_ITEM_Out];
|
||||
uint8_t ReportSizeFeatureBits = CurrReportIDInfo->ReportSizeBits[HID_REPORT_ITEM_Feature];
|
||||
|
||||
/* Print out the byte sizes of each report within the device */
|
||||
printf_P(PSTR(" + Report ID 0x%02" PRIX8 "\r\n"
|
||||
" - Input Data: %" PRId8 " bits (%" PRId8 " bytes)\r\n"
|
||||
" - Output Data: %" PRId8 " bits (%" PRId8 " bytes)\r\n"
|
||||
" - Feature Data: %" PRId8 " bits (%" PRId8 " bytes)\r\n"),
|
||||
CurrReportIDInfo->ReportID,
|
||||
ReportSizeInBits,
|
||||
((ReportSizeInBits >> 3) + ((ReportSizeInBits & 0x07) != 0)),
|
||||
ReportSizeOutBits,
|
||||
((ReportSizeOutBits >> 3) + ((ReportSizeOutBits & 0x07) != 0)),
|
||||
ReportSizeFeatureBits,
|
||||
((ReportSizeFeatureBits >> 3) + ((ReportSizeFeatureBits & 0x07) != 0)));
|
||||
}
|
||||
}
|
||||
|
||||
/** Prints a summary of the device's parsed and stored report items along with their attributes
|
||||
* to the serial port for display to the user.
|
||||
*/
|
||||
void OutputParsedReportItems(void)
|
||||
{
|
||||
printf_P(PSTR("\r\nReport Items (%" PRId8 " in Table):\r\n"), HIDReportInfo.TotalReportItems);
|
||||
|
||||
for (uint8_t ItemIndex = 0; ItemIndex < HIDReportInfo.TotalReportItems; ItemIndex++)
|
||||
{
|
||||
const HID_ReportItem_t* RItem = &HIDReportInfo.ReportItems[ItemIndex];
|
||||
|
||||
printf_P(PSTR(" + Item %" PRId8 ":\r\n"
|
||||
" - Report ID: 0x%02" PRIX8 "\r\n"
|
||||
" - Data Direction: %s\r\n"
|
||||
" - Item Flags: 0x%02" PRIX8 "\r\n"
|
||||
" - Item Offset (Bits): 0x%02" PRIX8 "\r\n"
|
||||
" - Item Size (Bits): 0x%02" PRIX8 "\r\n"
|
||||
" - Usage Page: 0x%04" PRIX16 "\r\n"
|
||||
" - Usage: 0x%04" PRIX16 "\r\n"
|
||||
" - Unit Type: 0x%08" PRIX32 "\r\n"
|
||||
" - Unit Exponent: 0x%02" PRIX8 "\r\n"
|
||||
" - Logical Minimum: 0x%08" PRIX32 "\r\n"
|
||||
" - Logical Maximum: 0x%08" PRIX32 "\r\n"
|
||||
" - Physical Minimum: 0x%08" PRIX32 "\r\n"
|
||||
" - Physical Maximum: 0x%08" PRIX32 "\r\n"
|
||||
" - Collection Path:\r\n"),
|
||||
ItemIndex,
|
||||
RItem->ReportID,
|
||||
((RItem->ItemType == HID_REPORT_ITEM_In) ? "IN" : ((RItem->ItemType == HID_REPORT_ITEM_Out) ? "OUT" : "FEATURE")),
|
||||
RItem->ItemFlags,
|
||||
RItem->BitOffset,
|
||||
RItem->Attributes.BitSize,
|
||||
RItem->Attributes.Usage.Page,
|
||||
RItem->Attributes.Usage.Usage,
|
||||
RItem->Attributes.Unit.Type,
|
||||
RItem->Attributes.Unit.Exponent,
|
||||
RItem->Attributes.Logical.Minimum,
|
||||
RItem->Attributes.Logical.Maximum,
|
||||
RItem->Attributes.Physical.Minimum,
|
||||
RItem->Attributes.Physical.Maximum);
|
||||
|
||||
OutputCollectionPath(RItem->CollectionPath);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prints the HID Collection path (along with each node's attributes) to the serial port
|
||||
* for display to the user, from the given starting node to the root node.
|
||||
*
|
||||
* \param[in] CollectionPath Starting HID Collection node to print
|
||||
*/
|
||||
void OutputCollectionPath(const HID_CollectionPath_t* const CollectionPath)
|
||||
{
|
||||
const HID_CollectionPath_t* CurrentNode = CollectionPath;
|
||||
|
||||
while (CurrentNode != NULL)
|
||||
{
|
||||
printf_P(PSTR(" |\r\n"
|
||||
" - Type: 0x%02" PRIX8 "\r\n"
|
||||
" - Usage: 0x%02" PRIX8 "\r\n"),
|
||||
CurrentNode->Type, CurrentNode->Usage);
|
||||
|
||||
CurrentNode = CurrentNode->Parent;
|
||||
}
|
||||
|
||||
printf_P(PSTR(" |\r\n"
|
||||
" END\r\n"));
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
Serial_Init(9600, false);
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Create a stdio stream for the serial port for stdin and stdout */
|
||||
Serial_CreateStream(NULL);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
|
||||
* starts the library USB task to begin the enumeration and USB management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceAttached(void)
|
||||
{
|
||||
puts_P(PSTR("Device Attached.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and
|
||||
* stops the library USB task management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceUnattached(void)
|
||||
{
|
||||
puts_P(PSTR("\r\nDevice Unattached.\r\n"));
|
||||
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);
|
||||
|
||||
uint16_t ConfigDescriptorSize;
|
||||
uint8_t ConfigDescriptorData[512];
|
||||
|
||||
if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
|
||||
sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
|
||||
{
|
||||
puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (HID_Host_ConfigurePipes(&Device_HID_Interface,
|
||||
ConfigDescriptorSize, ConfigDescriptorData) != HID_ENUMERROR_NoError)
|
||||
{
|
||||
puts_P(PSTR("Attached Device Not a Valid HID Device.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
puts_P(PSTR("Error Setting Device Configuration.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (HID_Host_SetReportProtocol(&Device_HID_Interface) != 0)
|
||||
{
|
||||
puts_P(PSTR("Error Setting Report Protocol Mode.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
USB_Host_SetDeviceConfiguration(0);
|
||||
return;
|
||||
}
|
||||
|
||||
puts_P(PSTR("HID Device Enumerated.\r\n"));
|
||||
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();
|
||||
|
||||
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
|
||||
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while
|
||||
* enumerating an attached USB device.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
|
||||
const uint8_t SubErrorCode)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
|
||||
" -- Error Code %d\r\n"
|
||||
" -- Sub Error Code %d\r\n"
|
||||
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store
|
||||
* an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items
|
||||
* we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would
|
||||
* have occupied).
|
||||
*
|
||||
* \param[in] CurrentItem Pointer to the item the HID report parser is currently working with
|
||||
*
|
||||
* \return Boolean true if the item should be stored into the HID report structure, false if it should be discarded
|
||||
*/
|
||||
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for HIDReportViewer.c.
|
||||
*/
|
||||
|
||||
#ifndef _HID_REPORT_VIEWER_H_
|
||||
#define _HID_REPORT_VIEWER_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/Misc/TerminalCodes.h>
|
||||
#include <LUFA/Drivers/Peripheral/Serial.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/USB/USB.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)
|
||||
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
|
||||
#define LEDMASK_USB_BUSY (LEDS_LED1 | LEDS_LED3 | LEDS_LED4)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void RetrieveDeviceData(void);
|
||||
void OutputReportSizes(void);
|
||||
void OutputParsedReportItems(void);
|
||||
void OutputCollectionPath(const HID_CollectionPath_t* const CollectionPath);
|
||||
|
||||
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);
|
||||
|
||||
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for HIDReportViewer.c.
|
||||
*/
|
||||
|
||||
#ifndef _HID_REPORT_VIEWER_H_
|
||||
#define _HID_REPORT_VIEWER_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/Misc/TerminalCodes.h>
|
||||
#include <LUFA/Drivers/Peripheral/Serial.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/USB/USB.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)
|
||||
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
|
||||
#define LEDMASK_USB_BUSY (LEDS_LED1 | LEDS_LED3 | LEDS_LED4)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void RetrieveDeviceData(void);
|
||||
void OutputReportSizes(void);
|
||||
void OutputParsedReportItems(void);
|
||||
void OutputCollectionPath(const HID_CollectionPath_t* const CollectionPath);
|
||||
|
||||
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);
|
||||
|
||||
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
/** \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 HID Device Report Viewer Programmer Project
|
||||
*
|
||||
* \section Sec_Compat Project Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this project.
|
||||
*
|
||||
* - 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 \n
|
||||
* USBIF HID Usage Tables</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Usable Speeds:</b></td>
|
||||
* <td>Low Speed Mode \n
|
||||
* Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section Sec_Description Project Description:
|
||||
*
|
||||
* Firmware for a HID Report viewer. This project is designed to aid in the debugging of USB HID Hosts, where the contents of an
|
||||
* unknown HID device's HID Report need to be examined. Once a HID device has been plugged into this application, the HID report
|
||||
* descriptor will be parsed using the internal LUFA HID report parser, and the results dumped to the serial port in a human
|
||||
* readable format. This output will contain information on the sizes of the reports within the device's HID interface, as well as
|
||||
* information on each report element (size, usage, minimum/maximum values, etc.).
|
||||
*
|
||||
* \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>
|
||||
*/
|
||||
|
||||
/** \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 HID Device Report Viewer Programmer Project
|
||||
*
|
||||
* \section Sec_Compat Project Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this project.
|
||||
*
|
||||
* - 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 \n
|
||||
* USBIF HID Usage Tables</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Usable Speeds:</b></td>
|
||||
* <td>Low Speed Mode \n
|
||||
* Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section Sec_Description Project Description:
|
||||
*
|
||||
* Firmware for a HID Report viewer. This project is designed to aid in the debugging of USB HID Hosts, where the contents of an
|
||||
* unknown HID device's HID Report need to be examined. Once a HID device has been plugged into this application, the HID report
|
||||
* descriptor will be parsed using the internal LUFA HID report parser, and the results dumped to the serial port in a human
|
||||
* readable format. This output will contain information on the sizes of the reports within the device's HID interface, as well as
|
||||
* information on each report element (size, usage, minimum/maximum values, etc.).
|
||||
*
|
||||
* \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>
|
||||
*/
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,329 +1,329 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
||||
* computer-readable structures which the host requests upon device enumeration, to determine
|
||||
* the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
/** 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(01.10),
|
||||
.Class = USB_CSCP_NoDeviceClass,
|
||||
.SubClass = USB_CSCP_NoDeviceSubclass,
|
||||
.Protocol = USB_CSCP_NoDeviceProtocol,
|
||||
|
||||
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
||||
|
||||
.VendorID = 0x03EB,
|
||||
.ProductID = 0x2048,
|
||||
.ReleaseNumber = VERSION_BCD(00.01),
|
||||
|
||||
.ManufacturerStrIndex = 0x01,
|
||||
.ProductStrIndex = 0x02,
|
||||
.SerialNumStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
|
||||
};
|
||||
|
||||
/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
|
||||
* of the device in one of its supported configurations, including information about any device interfaces
|
||||
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
|
||||
* a configuration so that the host may correctly communicate with the USB device.
|
||||
*/
|
||||
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 = 2,
|
||||
|
||||
.ConfigurationNumber = 1,
|
||||
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
|
||||
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||
},
|
||||
|
||||
.Audio_ControlInterface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 0,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 0,
|
||||
|
||||
.Class = AUDIO_CSCP_AudioClass,
|
||||
.SubClass = AUDIO_CSCP_ControlSubclass,
|
||||
.Protocol = AUDIO_CSCP_ControlProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.Audio_ControlInterface_SPC =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_Header,
|
||||
|
||||
.ACSpecification = VERSION_BCD(01.00),
|
||||
.TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t),
|
||||
|
||||
.InCollection = 1,
|
||||
.InterfaceNumber = 1,
|
||||
},
|
||||
|
||||
.Audio_StreamInterface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 1,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 2,
|
||||
|
||||
.Class = AUDIO_CSCP_AudioClass,
|
||||
.SubClass = AUDIO_CSCP_MIDIStreamingSubclass,
|
||||
.Protocol = AUDIO_CSCP_StreamingProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.Audio_StreamInterface_SPC =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_General,
|
||||
|
||||
.AudioSpecification = VERSION_BCD(01.00),
|
||||
|
||||
.TotalLength = (sizeof(USB_Descriptor_Configuration_t) -
|
||||
offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC))
|
||||
},
|
||||
|
||||
.MIDI_In_Jack_Emb =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
|
||||
|
||||
.JackType = MIDI_JACKTYPE_Embedded,
|
||||
.JackID = 0x01,
|
||||
|
||||
.JackStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MIDI_In_Jack_Ext =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
|
||||
|
||||
.JackType = MIDI_JACKTYPE_External,
|
||||
.JackID = 0x02,
|
||||
|
||||
.JackStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MIDI_Out_Jack_Emb =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
|
||||
|
||||
.JackType = MIDI_JACKTYPE_Embedded,
|
||||
.JackID = 0x03,
|
||||
|
||||
.NumberOfPins = 1,
|
||||
.SourceJackID = {0x02},
|
||||
.SourcePinID = {0x01},
|
||||
|
||||
.JackStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MIDI_Out_Jack_Ext =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
|
||||
|
||||
.JackType = MIDI_JACKTYPE_External,
|
||||
.JackID = 0x04,
|
||||
|
||||
.NumberOfPins = 1,
|
||||
.SourceJackID = {0x01},
|
||||
.SourcePinID = {0x01},
|
||||
|
||||
.JackStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MIDI_In_Jack_Endpoint =
|
||||
{
|
||||
.Endpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = MIDI_STREAM_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.Refresh = 0,
|
||||
.SyncEndpointNumber = 0
|
||||
},
|
||||
|
||||
.MIDI_In_Jack_Endpoint_SPC =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t), .Type = DTYPE_CSEndpoint},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
|
||||
|
||||
.TotalEmbeddedJacks = 0x01,
|
||||
.AssociatedJackID = {0x01}
|
||||
},
|
||||
|
||||
.MIDI_Out_Jack_Endpoint =
|
||||
{
|
||||
.Endpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | MIDI_STREAM_IN_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = MIDI_STREAM_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.Refresh = 0,
|
||||
.SyncEndpointNumber = 0
|
||||
},
|
||||
|
||||
.MIDI_Out_Jack_Endpoint_SPC =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t), .Type = DTYPE_CSEndpoint},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
|
||||
|
||||
.TotalEmbeddedJacks = 0x01,
|
||||
.AssociatedJackID = {0x03}
|
||||
}
|
||||
};
|
||||
|
||||
/** 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 =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = {LANGUAGE_ID_ENG}
|
||||
};
|
||||
|
||||
/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
|
||||
* form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
|
||||
* Descriptor.
|
||||
*/
|
||||
const USB_Descriptor_String_t PROGMEM ManufacturerString =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = 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 =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(14), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = L"LUFA MIDI 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 0x00:
|
||||
Address = &LanguageString;
|
||||
Size = pgm_read_byte(&LanguageString.Header.Size);
|
||||
break;
|
||||
case 0x01:
|
||||
Address = &ManufacturerString;
|
||||
Size = pgm_read_byte(&ManufacturerString.Header.Size);
|
||||
break;
|
||||
case 0x02:
|
||||
Address = &ProductString;
|
||||
Size = pgm_read_byte(&ProductString.Header.Size);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
||||
* computer-readable structures which the host requests upon device enumeration, to determine
|
||||
* the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
/** 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(01.10),
|
||||
.Class = USB_CSCP_NoDeviceClass,
|
||||
.SubClass = USB_CSCP_NoDeviceSubclass,
|
||||
.Protocol = USB_CSCP_NoDeviceProtocol,
|
||||
|
||||
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
||||
|
||||
.VendorID = 0x03EB,
|
||||
.ProductID = 0x2048,
|
||||
.ReleaseNumber = VERSION_BCD(00.01),
|
||||
|
||||
.ManufacturerStrIndex = 0x01,
|
||||
.ProductStrIndex = 0x02,
|
||||
.SerialNumStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
|
||||
};
|
||||
|
||||
/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
|
||||
* of the device in one of its supported configurations, including information about any device interfaces
|
||||
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
|
||||
* a configuration so that the host may correctly communicate with the USB device.
|
||||
*/
|
||||
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 = 2,
|
||||
|
||||
.ConfigurationNumber = 1,
|
||||
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
|
||||
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||
},
|
||||
|
||||
.Audio_ControlInterface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 0,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 0,
|
||||
|
||||
.Class = AUDIO_CSCP_AudioClass,
|
||||
.SubClass = AUDIO_CSCP_ControlSubclass,
|
||||
.Protocol = AUDIO_CSCP_ControlProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.Audio_ControlInterface_SPC =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_Header,
|
||||
|
||||
.ACSpecification = VERSION_BCD(01.00),
|
||||
.TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t),
|
||||
|
||||
.InCollection = 1,
|
||||
.InterfaceNumber = 1,
|
||||
},
|
||||
|
||||
.Audio_StreamInterface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = 1,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 2,
|
||||
|
||||
.Class = AUDIO_CSCP_AudioClass,
|
||||
.SubClass = AUDIO_CSCP_MIDIStreamingSubclass,
|
||||
.Protocol = AUDIO_CSCP_StreamingProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.Audio_StreamInterface_SPC =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_General,
|
||||
|
||||
.AudioSpecification = VERSION_BCD(01.00),
|
||||
|
||||
.TotalLength = (sizeof(USB_Descriptor_Configuration_t) -
|
||||
offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC))
|
||||
},
|
||||
|
||||
.MIDI_In_Jack_Emb =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
|
||||
|
||||
.JackType = MIDI_JACKTYPE_Embedded,
|
||||
.JackID = 0x01,
|
||||
|
||||
.JackStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MIDI_In_Jack_Ext =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
|
||||
|
||||
.JackType = MIDI_JACKTYPE_External,
|
||||
.JackID = 0x02,
|
||||
|
||||
.JackStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MIDI_Out_Jack_Emb =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
|
||||
|
||||
.JackType = MIDI_JACKTYPE_Embedded,
|
||||
.JackID = 0x03,
|
||||
|
||||
.NumberOfPins = 1,
|
||||
.SourceJackID = {0x02},
|
||||
.SourcePinID = {0x01},
|
||||
|
||||
.JackStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MIDI_Out_Jack_Ext =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
|
||||
|
||||
.JackType = MIDI_JACKTYPE_External,
|
||||
.JackID = 0x04,
|
||||
|
||||
.NumberOfPins = 1,
|
||||
.SourceJackID = {0x01},
|
||||
.SourcePinID = {0x01},
|
||||
|
||||
.JackStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.MIDI_In_Jack_Endpoint =
|
||||
{
|
||||
.Endpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = MIDI_STREAM_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.Refresh = 0,
|
||||
.SyncEndpointNumber = 0
|
||||
},
|
||||
|
||||
.MIDI_In_Jack_Endpoint_SPC =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t), .Type = DTYPE_CSEndpoint},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
|
||||
|
||||
.TotalEmbeddedJacks = 0x01,
|
||||
.AssociatedJackID = {0x01}
|
||||
},
|
||||
|
||||
.MIDI_Out_Jack_Endpoint =
|
||||
{
|
||||
.Endpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | MIDI_STREAM_IN_EPNUM),
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = MIDI_STREAM_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
|
||||
.Refresh = 0,
|
||||
.SyncEndpointNumber = 0
|
||||
},
|
||||
|
||||
.MIDI_Out_Jack_Endpoint_SPC =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t), .Type = DTYPE_CSEndpoint},
|
||||
.Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
|
||||
|
||||
.TotalEmbeddedJacks = 0x01,
|
||||
.AssociatedJackID = {0x03}
|
||||
}
|
||||
};
|
||||
|
||||
/** 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 =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = {LANGUAGE_ID_ENG}
|
||||
};
|
||||
|
||||
/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
|
||||
* form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
|
||||
* Descriptor.
|
||||
*/
|
||||
const USB_Descriptor_String_t PROGMEM ManufacturerString =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = 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 =
|
||||
{
|
||||
.Header = {.Size = USB_STRING_LEN(14), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = L"LUFA MIDI 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 0x00:
|
||||
Address = &LanguageString;
|
||||
Size = pgm_read_byte(&LanguageString.Header.Size);
|
||||
break;
|
||||
case 0x01:
|
||||
Address = &ManufacturerString;
|
||||
Size = pgm_read_byte(&ManufacturerString.Header.Size);
|
||||
break;
|
||||
case 0x02:
|
||||
Address = &ProductString;
|
||||
Size = pgm_read_byte(&ProductString.Header.Size);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for Descriptors.c.
|
||||
*/
|
||||
|
||||
#ifndef _DESCRIPTORS_H_
|
||||
#define _DESCRIPTORS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Endpoint number of the MIDI streaming data IN endpoint, for device-to-host data transfers. */
|
||||
#define MIDI_STREAM_IN_EPNUM 2
|
||||
|
||||
/** Endpoint number of the MIDI streaming data OUT endpoint, for host-to-device data transfers. */
|
||||
#define MIDI_STREAM_OUT_EPNUM 1
|
||||
|
||||
/** Endpoint size in bytes of the Audio isochronous streaming data IN and OUT endpoints. */
|
||||
#define MIDI_STREAM_EPSIZE 64
|
||||
|
||||
/* 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;
|
||||
|
||||
// MIDI Audio Control Interface
|
||||
USB_Descriptor_Interface_t Audio_ControlInterface;
|
||||
USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
|
||||
|
||||
// MIDI Audio Streaming Interface
|
||||
USB_Descriptor_Interface_t Audio_StreamInterface;
|
||||
USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
|
||||
USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
|
||||
USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
|
||||
USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
|
||||
USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
|
||||
USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
|
||||
USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
|
||||
USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
|
||||
USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
|
||||
} USB_Descriptor_Configuration_t;
|
||||
|
||||
/* 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
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for Descriptors.c.
|
||||
*/
|
||||
|
||||
#ifndef _DESCRIPTORS_H_
|
||||
#define _DESCRIPTORS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Endpoint number of the MIDI streaming data IN endpoint, for device-to-host data transfers. */
|
||||
#define MIDI_STREAM_IN_EPNUM 2
|
||||
|
||||
/** Endpoint number of the MIDI streaming data OUT endpoint, for host-to-device data transfers. */
|
||||
#define MIDI_STREAM_OUT_EPNUM 1
|
||||
|
||||
/** Endpoint size in bytes of the Audio isochronous streaming data IN and OUT endpoints. */
|
||||
#define MIDI_STREAM_EPSIZE 64
|
||||
|
||||
/* 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;
|
||||
|
||||
// MIDI Audio Control Interface
|
||||
USB_Descriptor_Interface_t Audio_ControlInterface;
|
||||
USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
|
||||
|
||||
// MIDI Audio Streaming Interface
|
||||
USB_Descriptor_Interface_t Audio_StreamInterface;
|
||||
USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
|
||||
USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
|
||||
USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
|
||||
USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
|
||||
USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
|
||||
USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
|
||||
USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
|
||||
USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
|
||||
USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
|
||||
} USB_Descriptor_Configuration_t;
|
||||
|
||||
/* 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
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,245 +1,245 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the MIDI demo. This file contains the main tasks of
|
||||
* the demo and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "MIDIToneGenerator.h"
|
||||
|
||||
/** LUFA MIDI Class driver interface configuration and state information. This structure is
|
||||
* passed to all MIDI Class driver functions, so that multiple instances of the same class
|
||||
* within a device can be differentiated from one another.
|
||||
*/
|
||||
USB_ClassInfo_MIDI_Device_t Keyboard_MIDI_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.StreamingInterfaceNumber = 1,
|
||||
|
||||
.DataINEndpointNumber = MIDI_STREAM_IN_EPNUM,
|
||||
.DataINEndpointSize = MIDI_STREAM_EPSIZE,
|
||||
.DataINEndpointDoubleBank = false,
|
||||
|
||||
.DataOUTEndpointNumber = MIDI_STREAM_OUT_EPNUM,
|
||||
.DataOUTEndpointSize = MIDI_STREAM_EPSIZE,
|
||||
.DataOUTEndpointDoubleBank = false,
|
||||
},
|
||||
};
|
||||
|
||||
/** 8-bit 256 entry Sine Wave lookup table */
|
||||
static const uint8_t SineTable[256] =
|
||||
{
|
||||
128, 131, 134, 137, 140, 143, 146, 149, 152, 156, 159, 162, 165, 168, 171, 174,
|
||||
176, 179, 182, 185, 188, 191, 193, 196, 199, 201, 204, 206, 209, 211, 213, 216,
|
||||
218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 237, 239, 240, 242, 243, 245,
|
||||
246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 254, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 254, 254, 253, 252, 252, 251, 250, 249, 248, 247,
|
||||
246, 245, 243, 242, 240, 239, 237, 236, 234, 232, 230, 228, 226, 224, 222, 220,
|
||||
218, 216, 213, 211, 209, 206, 204, 201, 199, 196, 193, 191, 188, 185, 182, 179,
|
||||
176, 174, 171, 168, 165, 162, 159, 156, 152, 149, 146, 143, 140, 137, 134, 131,
|
||||
128, 124, 121, 118, 115, 112, 109, 106, 103, 99, 96, 93, 90, 87, 84, 81,
|
||||
79, 76, 73, 70, 67, 64, 62, 59, 56, 54, 51, 49, 46, 44, 42, 39,
|
||||
37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 18, 16, 15, 13, 12, 10,
|
||||
9, 8, 7, 6, 5, 4, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 12, 13, 15, 16, 18, 19, 21, 23, 25, 27, 29, 31, 33, 35,
|
||||
37, 39, 42, 44, 46, 49, 51, 54, 56, 59, 62, 64, 67, 70, 73, 76,
|
||||
79, 81, 84, 87, 90, 93, 96, 99, 103, 106, 109, 112, 115, 118, 121, 124,
|
||||
};
|
||||
|
||||
/** Array of structures describing each note being generated */
|
||||
static DDSNoteData NoteData[MAX_SIMULTANEOUS_NOTES];
|
||||
|
||||
|
||||
/** 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);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
MIDI_EventPacket_t ReceivedMIDIEvent;
|
||||
if (MIDI_Device_ReceiveEventPacket(&Keyboard_MIDI_Interface, &ReceivedMIDIEvent))
|
||||
{
|
||||
if ((ReceivedMIDIEvent.Command == (MIDI_COMMAND_NOTE_ON >> 4)) && ((ReceivedMIDIEvent.Data1 & 0x0F) == 0))
|
||||
{
|
||||
DDSNoteData* LRUNoteStruct = &NoteData[0];
|
||||
|
||||
/* Find a free entry in the note table to use for the note being turned on */
|
||||
for (uint8_t i = 0; i < MAX_SIMULTANEOUS_NOTES; i++)
|
||||
{
|
||||
/* Check if the note is unused */
|
||||
if (!(NoteData[i].Pitch))
|
||||
{
|
||||
/* If a note is unused, it's age is essentially infinite - always prefer unused not entries */
|
||||
LRUNoteStruct = &NoteData[i];
|
||||
break;
|
||||
}
|
||||
else if (NoteData[i].LRUAge >= LRUNoteStruct->LRUAge)
|
||||
{
|
||||
/* If an older entry that the current entry has been found, prefer overwriting that one */
|
||||
LRUNoteStruct = &NoteData[i];
|
||||
}
|
||||
|
||||
NoteData[i].LRUAge++;
|
||||
}
|
||||
|
||||
/* Update the oldest note entry with the new note data and reset its age */
|
||||
LRUNoteStruct->Pitch = ReceivedMIDIEvent.Data2;
|
||||
LRUNoteStruct->TableIncrement = (uint32_t)(BASE_INCREMENT * SCALE_FACTOR) +
|
||||
((uint32_t)(BASE_INCREMENT * NOTE_OCTIVE_RATIO * SCALE_FACTOR) *
|
||||
(ReceivedMIDIEvent.Data2 - BASE_PITCH_INDEX));
|
||||
LRUNoteStruct->TablePosition = 0;
|
||||
LRUNoteStruct->LRUAge = 0;
|
||||
|
||||
/* Turn on indicator LED to indicate note generation activity */
|
||||
LEDs_SetAllLEDs(LEDS_LED1);
|
||||
}
|
||||
else if ((ReceivedMIDIEvent.Command == (MIDI_COMMAND_NOTE_OFF >> 4)) && ((ReceivedMIDIEvent.Data1 & 0x0F) == 0))
|
||||
{
|
||||
bool FoundActiveNote = false;
|
||||
|
||||
/* Find the note in the note table to turn off */
|
||||
for (uint8_t i = 0; i < MAX_SIMULTANEOUS_NOTES; i++)
|
||||
{
|
||||
if (NoteData[i].Pitch == ReceivedMIDIEvent.Data2)
|
||||
NoteData[i].Pitch = 0;
|
||||
else if (NoteData[i].Pitch)
|
||||
FoundActiveNote = true;
|
||||
}
|
||||
|
||||
/* If all notes off, turn off the indicator LED */
|
||||
if (!(FoundActiveNote))
|
||||
LEDs_SetAllLEDs(LEDS_NO_LEDS);
|
||||
}
|
||||
}
|
||||
|
||||
MIDI_Device_USBTask(&Keyboard_MIDI_Interface);
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** ISR to handle the reloading of the PWM timer with the next sample. */
|
||||
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
|
||||
{
|
||||
uint16_t MixedSample = 0;
|
||||
|
||||
/* Sum together all the active notes to form a single sample */
|
||||
for (uint8_t i = 0; i < MAX_SIMULTANEOUS_NOTES; i++)
|
||||
{
|
||||
/* A non-zero pitch indicates the note is active */
|
||||
if (NoteData[i].Pitch)
|
||||
{
|
||||
/* Use the top 8 bits of the table position as the sample table index */
|
||||
uint8_t TableIndex = (NoteData[i].TablePosition >> 24);
|
||||
|
||||
/* Add the new tone sample to the accumulator and increment the table position */
|
||||
MixedSample += SineTable[TableIndex];
|
||||
NoteData[i].TablePosition += NoteData[i].TableIncrement;
|
||||
}
|
||||
}
|
||||
|
||||
/* Output clamped mixed sample value to the PWM */
|
||||
OCR3A = (MixedSample <= 0xFF) ? MixedSample : 0xFF;
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Sample reload timer initialization */
|
||||
TIMSK0 = (1 << OCIE0A);
|
||||
OCR0A = (VIRTUAL_SAMPLE_TABLE_SIZE / 8);
|
||||
TCCR0A = (1 << WGM01); // CTC mode
|
||||
TCCR0B = (1 << CS01); // Fcpu/8 speed
|
||||
|
||||
/* Set speaker as output */
|
||||
DDRC |= (1 << 6);
|
||||
|
||||
/* PWM speaker timer initialization */
|
||||
TCCR3A = ((1 << WGM31) | (1 << COM3A1) | (1 << COM3A0)); // Set on match, clear on TOP
|
||||
TCCR3B = ((1 << WGM32) | (1 << CS30)); // Fast 8-Bit PWM, Fcpu speed
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Connection event. */
|
||||
void EVENT_USB_Device_Connect(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
|
||||
/* Set speaker as output */
|
||||
DDRC |= (1 << 6);
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Disconnection event. */
|
||||
void EVENT_USB_Device_Disconnect(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
|
||||
/* Disable any notes currently being played */
|
||||
for (uint8_t i = 0; i < MAX_SIMULTANEOUS_NOTES; i++)
|
||||
NoteData[i].Pitch = 0;
|
||||
|
||||
/* Set speaker as input to reduce current draw */
|
||||
DDRC &= ~(1 << 6);
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Configuration Changed event. */
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
bool ConfigSuccess = true;
|
||||
|
||||
ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&Keyboard_MIDI_Interface);
|
||||
|
||||
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Control Request event. */
|
||||
void EVENT_USB_Device_ControlRequest(void)
|
||||
{
|
||||
MIDI_Device_ProcessControlRequest(&Keyboard_MIDI_Interface);
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the MIDI demo. This file contains the main tasks of
|
||||
* the demo and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "MIDIToneGenerator.h"
|
||||
|
||||
/** LUFA MIDI Class driver interface configuration and state information. This structure is
|
||||
* passed to all MIDI Class driver functions, so that multiple instances of the same class
|
||||
* within a device can be differentiated from one another.
|
||||
*/
|
||||
USB_ClassInfo_MIDI_Device_t Keyboard_MIDI_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.StreamingInterfaceNumber = 1,
|
||||
|
||||
.DataINEndpointNumber = MIDI_STREAM_IN_EPNUM,
|
||||
.DataINEndpointSize = MIDI_STREAM_EPSIZE,
|
||||
.DataINEndpointDoubleBank = false,
|
||||
|
||||
.DataOUTEndpointNumber = MIDI_STREAM_OUT_EPNUM,
|
||||
.DataOUTEndpointSize = MIDI_STREAM_EPSIZE,
|
||||
.DataOUTEndpointDoubleBank = false,
|
||||
},
|
||||
};
|
||||
|
||||
/** 8-bit 256 entry Sine Wave lookup table */
|
||||
static const uint8_t SineTable[256] =
|
||||
{
|
||||
128, 131, 134, 137, 140, 143, 146, 149, 152, 156, 159, 162, 165, 168, 171, 174,
|
||||
176, 179, 182, 185, 188, 191, 193, 196, 199, 201, 204, 206, 209, 211, 213, 216,
|
||||
218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 237, 239, 240, 242, 243, 245,
|
||||
246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 254, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 254, 254, 253, 252, 252, 251, 250, 249, 248, 247,
|
||||
246, 245, 243, 242, 240, 239, 237, 236, 234, 232, 230, 228, 226, 224, 222, 220,
|
||||
218, 216, 213, 211, 209, 206, 204, 201, 199, 196, 193, 191, 188, 185, 182, 179,
|
||||
176, 174, 171, 168, 165, 162, 159, 156, 152, 149, 146, 143, 140, 137, 134, 131,
|
||||
128, 124, 121, 118, 115, 112, 109, 106, 103, 99, 96, 93, 90, 87, 84, 81,
|
||||
79, 76, 73, 70, 67, 64, 62, 59, 56, 54, 51, 49, 46, 44, 42, 39,
|
||||
37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 18, 16, 15, 13, 12, 10,
|
||||
9, 8, 7, 6, 5, 4, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 12, 13, 15, 16, 18, 19, 21, 23, 25, 27, 29, 31, 33, 35,
|
||||
37, 39, 42, 44, 46, 49, 51, 54, 56, 59, 62, 64, 67, 70, 73, 76,
|
||||
79, 81, 84, 87, 90, 93, 96, 99, 103, 106, 109, 112, 115, 118, 121, 124,
|
||||
};
|
||||
|
||||
/** Array of structures describing each note being generated */
|
||||
static DDSNoteData NoteData[MAX_SIMULTANEOUS_NOTES];
|
||||
|
||||
|
||||
/** 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);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
MIDI_EventPacket_t ReceivedMIDIEvent;
|
||||
if (MIDI_Device_ReceiveEventPacket(&Keyboard_MIDI_Interface, &ReceivedMIDIEvent))
|
||||
{
|
||||
if ((ReceivedMIDIEvent.Command == (MIDI_COMMAND_NOTE_ON >> 4)) && ((ReceivedMIDIEvent.Data1 & 0x0F) == 0))
|
||||
{
|
||||
DDSNoteData* LRUNoteStruct = &NoteData[0];
|
||||
|
||||
/* Find a free entry in the note table to use for the note being turned on */
|
||||
for (uint8_t i = 0; i < MAX_SIMULTANEOUS_NOTES; i++)
|
||||
{
|
||||
/* Check if the note is unused */
|
||||
if (!(NoteData[i].Pitch))
|
||||
{
|
||||
/* If a note is unused, it's age is essentially infinite - always prefer unused not entries */
|
||||
LRUNoteStruct = &NoteData[i];
|
||||
break;
|
||||
}
|
||||
else if (NoteData[i].LRUAge >= LRUNoteStruct->LRUAge)
|
||||
{
|
||||
/* If an older entry that the current entry has been found, prefer overwriting that one */
|
||||
LRUNoteStruct = &NoteData[i];
|
||||
}
|
||||
|
||||
NoteData[i].LRUAge++;
|
||||
}
|
||||
|
||||
/* Update the oldest note entry with the new note data and reset its age */
|
||||
LRUNoteStruct->Pitch = ReceivedMIDIEvent.Data2;
|
||||
LRUNoteStruct->TableIncrement = (uint32_t)(BASE_INCREMENT * SCALE_FACTOR) +
|
||||
((uint32_t)(BASE_INCREMENT * NOTE_OCTIVE_RATIO * SCALE_FACTOR) *
|
||||
(ReceivedMIDIEvent.Data2 - BASE_PITCH_INDEX));
|
||||
LRUNoteStruct->TablePosition = 0;
|
||||
LRUNoteStruct->LRUAge = 0;
|
||||
|
||||
/* Turn on indicator LED to indicate note generation activity */
|
||||
LEDs_SetAllLEDs(LEDS_LED1);
|
||||
}
|
||||
else if ((ReceivedMIDIEvent.Command == (MIDI_COMMAND_NOTE_OFF >> 4)) && ((ReceivedMIDIEvent.Data1 & 0x0F) == 0))
|
||||
{
|
||||
bool FoundActiveNote = false;
|
||||
|
||||
/* Find the note in the note table to turn off */
|
||||
for (uint8_t i = 0; i < MAX_SIMULTANEOUS_NOTES; i++)
|
||||
{
|
||||
if (NoteData[i].Pitch == ReceivedMIDIEvent.Data2)
|
||||
NoteData[i].Pitch = 0;
|
||||
else if (NoteData[i].Pitch)
|
||||
FoundActiveNote = true;
|
||||
}
|
||||
|
||||
/* If all notes off, turn off the indicator LED */
|
||||
if (!(FoundActiveNote))
|
||||
LEDs_SetAllLEDs(LEDS_NO_LEDS);
|
||||
}
|
||||
}
|
||||
|
||||
MIDI_Device_USBTask(&Keyboard_MIDI_Interface);
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** ISR to handle the reloading of the PWM timer with the next sample. */
|
||||
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
|
||||
{
|
||||
uint16_t MixedSample = 0;
|
||||
|
||||
/* Sum together all the active notes to form a single sample */
|
||||
for (uint8_t i = 0; i < MAX_SIMULTANEOUS_NOTES; i++)
|
||||
{
|
||||
/* A non-zero pitch indicates the note is active */
|
||||
if (NoteData[i].Pitch)
|
||||
{
|
||||
/* Use the top 8 bits of the table position as the sample table index */
|
||||
uint8_t TableIndex = (NoteData[i].TablePosition >> 24);
|
||||
|
||||
/* Add the new tone sample to the accumulator and increment the table position */
|
||||
MixedSample += SineTable[TableIndex];
|
||||
NoteData[i].TablePosition += NoteData[i].TableIncrement;
|
||||
}
|
||||
}
|
||||
|
||||
/* Output clamped mixed sample value to the PWM */
|
||||
OCR3A = (MixedSample <= 0xFF) ? MixedSample : 0xFF;
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Sample reload timer initialization */
|
||||
TIMSK0 = (1 << OCIE0A);
|
||||
OCR0A = (VIRTUAL_SAMPLE_TABLE_SIZE / 8);
|
||||
TCCR0A = (1 << WGM01); // CTC mode
|
||||
TCCR0B = (1 << CS01); // Fcpu/8 speed
|
||||
|
||||
/* Set speaker as output */
|
||||
DDRC |= (1 << 6);
|
||||
|
||||
/* PWM speaker timer initialization */
|
||||
TCCR3A = ((1 << WGM31) | (1 << COM3A1) | (1 << COM3A0)); // Set on match, clear on TOP
|
||||
TCCR3B = ((1 << WGM32) | (1 << CS30)); // Fast 8-Bit PWM, Fcpu speed
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Connection event. */
|
||||
void EVENT_USB_Device_Connect(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
|
||||
/* Set speaker as output */
|
||||
DDRC |= (1 << 6);
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Disconnection event. */
|
||||
void EVENT_USB_Device_Disconnect(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
|
||||
/* Disable any notes currently being played */
|
||||
for (uint8_t i = 0; i < MAX_SIMULTANEOUS_NOTES; i++)
|
||||
NoteData[i].Pitch = 0;
|
||||
|
||||
/* Set speaker as input to reduce current draw */
|
||||
DDRC &= ~(1 << 6);
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Configuration Changed event. */
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
bool ConfigSuccess = true;
|
||||
|
||||
ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&Keyboard_MIDI_Interface);
|
||||
|
||||
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Control Request event. */
|
||||
void EVENT_USB_Device_ControlRequest(void)
|
||||
{
|
||||
MIDI_Device_ProcessControlRequest(&Keyboard_MIDI_Interface);
|
||||
}
|
||||
|
||||
@@ -1,108 +1,108 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for AudioOutput.c.
|
||||
*/
|
||||
|
||||
#ifndef _AUDIO_OUTPUT_H_
|
||||
#define _AUDIO_OUTPUT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Peripheral/ADC.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/USB/Class/MIDI.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)
|
||||
|
||||
/** Scale factor used to convert the floating point frequencies and ratios into a fixed point number */
|
||||
#define SCALE_FACTOR 65536
|
||||
|
||||
/** Base (lowest) allowable MIDI note frequency */
|
||||
#define BASE_FREQUENCY 27.5
|
||||
|
||||
/** Ratio between each note in an octave */
|
||||
#define NOTE_OCTIVE_RATIO 1.05946
|
||||
|
||||
/** Lowest valid MIDI pitch index */
|
||||
#define BASE_PITCH_INDEX 21
|
||||
|
||||
/** Maximum number of MIDI notes that can be played simultaneously */
|
||||
#define MAX_SIMULTANEOUS_NOTES 3
|
||||
|
||||
/** Number of samples in the virtual sample table (can be expanded to lower maximum frequency, but allow for
|
||||
* more simultaneous notes due to the reduced amount of processing time needed when the samples are spaced out)
|
||||
*/
|
||||
#define VIRTUAL_SAMPLE_TABLE_SIZE 512
|
||||
|
||||
/** Sample table increments per period for the base MIDI note frequency */
|
||||
#define BASE_INCREMENT (((F_CPU / VIRTUAL_SAMPLE_TABLE_SIZE / 2) / BASE_FREQUENCY))
|
||||
|
||||
/* Type Defines: */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t LRUAge;
|
||||
uint8_t Pitch;
|
||||
uint32_t TableIncrement;
|
||||
uint32_t TablePosition;
|
||||
} DDSNoteData;
|
||||
|
||||
/* 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_UnhandledControlRequest(void);
|
||||
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2011.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for AudioOutput.c.
|
||||
*/
|
||||
|
||||
#ifndef _AUDIO_OUTPUT_H_
|
||||
#define _AUDIO_OUTPUT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Peripheral/ADC.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/USB/Class/MIDI.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)
|
||||
|
||||
/** Scale factor used to convert the floating point frequencies and ratios into a fixed point number */
|
||||
#define SCALE_FACTOR 65536
|
||||
|
||||
/** Base (lowest) allowable MIDI note frequency */
|
||||
#define BASE_FREQUENCY 27.5
|
||||
|
||||
/** Ratio between each note in an octave */
|
||||
#define NOTE_OCTIVE_RATIO 1.05946
|
||||
|
||||
/** Lowest valid MIDI pitch index */
|
||||
#define BASE_PITCH_INDEX 21
|
||||
|
||||
/** Maximum number of MIDI notes that can be played simultaneously */
|
||||
#define MAX_SIMULTANEOUS_NOTES 3
|
||||
|
||||
/** Number of samples in the virtual sample table (can be expanded to lower maximum frequency, but allow for
|
||||
* more simultaneous notes due to the reduced amount of processing time needed when the samples are spaced out)
|
||||
*/
|
||||
#define VIRTUAL_SAMPLE_TABLE_SIZE 512
|
||||
|
||||
/** Sample table increments per period for the base MIDI note frequency */
|
||||
#define BASE_INCREMENT (((F_CPU / VIRTUAL_SAMPLE_TABLE_SIZE / 2) / BASE_FREQUENCY))
|
||||
|
||||
/* Type Defines: */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t LRUAge;
|
||||
uint8_t Pitch;
|
||||
uint32_t TableIncrement;
|
||||
uint32_t TablePosition;
|
||||
} DDSNoteData;
|
||||
|
||||
/* 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_UnhandledControlRequest(void);
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user