diff --git a/LUFA/BuildingLinkableLibraries.txt b/LUFA/BuildingLinkableLibraries.txt new file mode 100644 index 0000000000..51fb973b35 --- /dev/null +++ b/LUFA/BuildingLinkableLibraries.txt @@ -0,0 +1,22 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \page Page_BuildLibrary Building as a Linkable Library + * + * The LUFA library can be built as a proper linkable library (with the extention .a) under AVR-GCC, so that + * the library does not need to be recompiled with each revision of a user project. Instructions for creating + * a library from a given source tree can be found in the AVR-GCC user manual included in the WinAVR install + * /Docs/ directory. + * + * However, building the library is not recommended, as the static (compile-time) options will be + * unable to be changed without a recompilation of the LUFA code. Therefore, if the library is to be built + * from the LUFA source, it should be made to be application-specific and compiled with the static options + * that are required for each project (which should be recorded along with the library). + * + * Normal library use has the library components compiled in at the same point as the application code, as + * demonstrated in the library demos and applications. This is the preferred method, as the library is recompiled + * each time to ensure that all static options for a particular application are applied. + */ diff --git a/LUFA/ChangeLog.txt b/LUFA/ChangeLog.txt new file mode 100644 index 0000000000..830e31eef0 --- /dev/null +++ b/LUFA/ChangeLog.txt @@ -0,0 +1,400 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + + /** \page Page_ChangeLog Project Changelog + * + * \section Sec_ChangeLogXXXXXX Version XXXXXX + * + * - Added new BluetoothHost demo + * - Changed AVRISP Programmer descriptors to use a newly allocated 0x204F PID value + * - Fixed MagStripe project configuration descriptor containing an unused (blank) endpoint descriptor + * - Incorporated makefile changes by Denver Gingerich to retain compatibility with stock (non-WinAVR) AVR-GCC installations + * - Fixed makefile EEPROM programming targets programming FLASH data in addition to EEPROM data + * - LUFA devices now enumerate correctly with LUFA hosts + * - Fixed Configuration Descriptor search routine freezing when a comparitor returned a failure + * - Removed HID report item serial dump in the MouseHostWithParser and KeyboardHostWithParser - useful only for debugging, and + * slowed down the enumeration of HID devices too much + * - Increased the number of bits per track which can be read in the MagStripe project to 20480 when compiled for the AT90USBXXX6/7 + * - Fixed KeyboardMouse demo discarding the wIndex value in the REQ_GetReport request + * + * \section Sec_ChangeLog090209 Version 090209 + * + * - PWM timer mode in AudioOut demo changed to Fast PWM for speed + * - Updated Magstripe project to work with the latest hardware revision + * - Fixed library not responding to the BCERRI flag correctly in host mode, leading to device lockups + * - Fixed library handling Get Descriptor requests when not addressed as standard requests to the device or interface + * - Fixed serious data corruption issue in MassStorage demo dataflash write routine + * - Added new NO_CLEARSET_FEATURE_REQUEST compile time token + * - USB task now restores previous global interrupt state after execution, rather than forcing global interrupts to be enabled + * - Fixed USB_DeviceEnumerationComplete event firing after each configuration change, rather than once after the initial configuration + * - Added ENDPOINT_DOUBLEBANK_SUPPORTED() macros to Endpoint.h, altered ENDPOINT_MAX_SIZE() to allow user to specify endpoint + * - ENDPOINT_MAX_ENDPOINTS changed to ENDPOINT_TOTAL_ENDPOINTS, PIPE_MAX_PIPES changed to PIPE_TOTAL_PIPES + * - Endpoint and Pipe non-control stream functions now ensure endpoint or pipe is ready before reading or writing + * - Changed Teensy bootloader to use a watchdog reset when exiting rather than a software jump + * - Fixed integer promotion error in MassStorage and MassStorageHost demos, corrupting read/write transfers + * - SPI_SendByte is now SPI_TransferByte, added new SPI_SendByte and SPI_ReceiveByte functions for fast one-way transfer + * - MassStorage demo changed to use new fast one-way SPI transfers to increase throughput + * - MassStorage handling of Mass Storage Reset class request improved + * - Altered MassStorage demo dataflash block read code for speed + * - Added USB_IsSuspended global flag + * - Simplified internal Dual Mode (OTG) USB library code to reduce code size + * - Extended stream timeout period to 100ms from 50ms + * - Mass Storage Host demo commands now all return an error code from the Pipe_Stream_RW_ErrorCodes_t enum + * - Added SubErrorCode parameter to the USB_DeviceEnumerationFailed event + * - VBUS drop interrupt now disabled during the manual-to-auto VBUS delivery handoff + * - Simplified low level backend so that device/host mode initialization uses the same code paths + * - Added workaround for faulty Mass Storage devices which do not implement the required GET_MAX_LUN request + * - Removed buggy Telnet application from the RNDIS demo + * - Moved Mass Storage class requests in the Mass Storage Host demo to wrapper functions in MassStoreCommands.c + * - Fixed incorrect SCSI command size value in the Request Sense command in MassStoreCommands.c + * - Added SetProtocol request to HID class non-parser Mouse and Keyboard demos to force devices to use the correct Boot Protocol + * - Added new "dfu" and "flip" programming targets to project makefiles + * - HID_PARSE_Sucessful enum member typo corrected to HID_PARSE_Successful + * - Changed COLLECTION item strucutres in the HID descriptor parser to include the collection's Usage Page value + * - Serial driver now sets Tx line as output, enables pullup on Rx line + * - Fixed smaller USB AVRs raising multiple connection and disconnection events when NO_LIMITED_CONTROLLER_CONNECT is disabled + * - Added HOST_DEVICE_SETTLE_DELAY_MS to give the host delay after a device is connected before it is enumerated + * - Fixed KeyboardHostWithParser demo linking against the wrong global variables + * - Completed doxygen documentation of remaining library bootloaders, demos and projects + * - Fixed incorrect bootloader start address in the TeensyHID bootloader + * - Added HWB button whole-disk ASCII dump functionality to MassStoreHost demo + * - Replaced printf_P(PSTR("%c"), {Variable}) calls with putchar() for speed and size savings + * - Serial driver now accepts baud rates over 16-bits in size, added double speed flag option + * - Fixed incorrect callback abort return value in Pipe.c + * - Added new flip-ee and dfu-ee makefile targets (courtesy of Opendous Inc.) + * - Removed reboot-on-disconnect code from the TeensyHID bootloader, caused problems on some systems + * - Fixed AudioOutput and AudioInput demos looping on the endpoint data, rather than processing a sample at a time and returning + * each time the task runs to allow for other tasks to execute + * - Added support for the Atmel ATAVRUSBRF01 board + * - Added AVRISP Programmer Project, courtesy of Opendous Inc. + * - Fixed CDC Host demo not searching through both CDC interfaces for endpoints + * - Fixed incorrect Product String descriptor length in the DFU class bootloader + * + * \section Sec_ChangeLog081224 Version 081224 + * + * - MyUSB name changed to LUFA, the Lightweight USB Framework for AVRs + * - Fixed Mass Storage Host demo's MassStore_SendCommand() delay in the incorrect place + * - Fixed USBtoSerial demo not calling ReconfigureUSART() after a change in the line encoding + * - Fixed infinite loop in host mode Host-to-Device control transfers with data stages + * - HID report parser now supports devices with multiple reports in one interface via Report IDs + * - Fixed RZUSBSTICK board LED driver header incorrect macro definition order causing compile errors + * - Calling USB_Init() when the USB interface is already configured now forces a complete interface reset + * and re-enumeration - fixes MyUSB DFU bootloader not switching to app code correctly when soft reset used + * - Fixed "No newline at end of file" warning when stream callbacks are enabled + * - DFU bootloader now uses fixed signature bytes per device, rather than reading them out dynamically for size + * - Added new FIXED_CONTROL_ENDPOINT_SIZE and USE_SINGLE_DEVICE_CONFIGURATION switches to statically define certain values to + * reduce compiled binary size + * - Added new NO_LIMITED_CONTROLLER_CONNECT switch to prevent the library from trying to determine bus connection + * state from the suspension and wake up events on the smaller USB AVRs + * - Added summary of all library compile time tokens to the documentation + * - Added overview of the LUFA scheduler to the documentation + * - Removed MANUAL_PLL_CONTROL compile time token, replaced with a mask for the USB_Init() Options parameter + * - CDC bootloader now uses the correct non-far or far versions of the pgm_* functions depending on if RAMPZ is defined + * - Doxygen documentation now contains documentation on all the projects, bootloaders and most demos included with the library + * - CDC bootloader now runs user application when USB disconnected rather than waiting for a hard reset + * - MouseHostWithParser and KeyboardHostWithParser now support multiple-report devices + * - RNDIS demo can now close connections correctly using the new TCP_APP_CLOSECONNECTION() macro - used in Webserver + * - Fixed the DFU bootloader, no longer freezes up when certain files are programmed into an AVR, made reading/writing faster + * - Fixed mouse/joystick up/down movements reversed - HID mouse X/Y coordinates use a left-handed coordinate system, not a normal + * right-handed system + * - Added stub code to the CDC and USBtoSerial demos showing how to read and set the RS-232 handshake lines - not currently used in + * the demos, but the example code and supporting defines are now in place + * - Interrupts are now disabled when processing a control request in device mode, to avoid exceeding the strict control request + * timing requirements. + * - All demos now use a central StatusUpdate() function rather than direct calls to the board LED functions, so that the demos can + * easily be altered to show different LED combinations (or do something else entirely) as the demo's status changes + * - Removed LED commands from the CDC bootloader, unused by most AVR910 programming software + * - Fixed RNDIS demo ICMP ping requests echoing back incorrect data + * - Added DHCP server code to RNDIS demo, allowing for hands-free autoconfiguration on any PC + * - Fixed DFU bootloader PID value for the ATMEGA16U4 AVR + * - Endpoint and Pipe configuration functions now return an error code indicating success or failure + * - USB Reset in device mode now resets and disables all device endpoints + * - Added intermediate states to the host mode state machine, reducing the USB task blocking time to no more than 1ms explicitly per + * invocation when in host mode + * - Added support for the ATMEGA32U6 microcontroller + * - Added STATIC_ENDPOINT_CONFIGURATION compile time option, enabled in the bootloaders to minimize space usage + * - Removed redudant code from the USB device GetStatus() chapter 9 processing routine + * - Added new TeensyHID bootloader, compatible with the Teensy HID protocol (http://www.pjrc.com/teensy/) + * - Versions are now numbered by release dates, rather than arbitrary major/minor revision numbers + * - USB_RemoteWakeupEnabled is now correctly set and cleared by SetFeature and ClearFeature requests from the host + * - Changed prototype of GetDescriptor, so that it now returns the descriptor size (or zero if the descriptor doesn't exist) + * rather than passing the size back to the caller through a parameter and returning a boolean + * + * \section Sec_ChangeLog153 Version 1.5.3 - Released 2nd October, 2008 + * + * - Fixed CDC bootloader using pgmspace macros for some descriptors inappropriately + * - Updated all Mouse and Keyboard device demos to include boot protocol support (now works in BIOS) + * - Renamed bootloader directories to remove spaces, which were causing build problems on several OSes + * - Removed serial number strings from all but the MassStore demo where it is required - users were not + * modifing the code to either ommit the descriptor or use a unique serial per device causing problems + * when multiple units of the same device were plugged in at the same time + * - AudioOutput and AudioInput demos now correctly silence endpoints when not enabled by the host + * - Added KeyboardMouse demo (Keyboard and Mouse functionality combined into a single demo) + * - Added DriverStubs directory to house board level driver templates, to make MyUSB compatible custom board + * driver creation easier + * - Extended MassStorage demo to support multiple LUNs, 2 by default + * - Fixed incorrect device address mask, preventing the device from enumerating with addresses larger than 63 + * - Fixed incorrect data direction mask in the GetStatus standard request, preventing it from being handled + * - Fixed incorrect GetStatus standard request for endpoints, now returns the endpoint STALL status correctly + * - Added in new USB_RemoteWakeupEnabled and USB_CurrentlySelfPowered flags rather than using fixed values + * - Added DualCDC demo to demonstrate the use of Interface Association Descriptors + * - Added pipe NAK detection and clearing API + * - Added pipe status change (NAK, STALL, etc.) interrupt API + * - Fixed MassStorageHost demo so that it no longer freezes randomly when issuing several commands in a row + * - Host demos configuration descriptor routines now return a unique error code when the returned data does + * not have a valid configuration descriptor header + * - Added Endpoint_WaitUntilReady() and Pipe_WaitUntilReady() functions + * - Stream functions now have software timeouts, timeout period can be set by the USB_STREAM_TIMEOUT_MS token + * - All demos now pass the USB.org automated Chapter 9 device compliance tests + * - All HID demos now pass the USB.org automated HID compliance tests + * - Polling interval of the interrupt endpoint in the CDC based demos changed to 0xFF to fix problems on Linux systems + * - Changed stream functions to accept a new callback function, with NO_STREAM_CALLBACKS used to disable all callbacks + * - Mass Storage demo dataflash management routines changed to use the endpoint stream functions + * - Added AVRStudio project files for each demo in addition to the existing Programmer's Notepad master project file + * - Re-added call to ReconfigureUSART() in USBtoSerial SetLineCoding request, so that baud rate changes + * are reflected in the hardware (change was previously lost) + * + * + * \section Sec_ChangeLog152 Version 1.5.2 - Released 31st July, 2008 + * + * - Fixed SwapEndian_32() function in Common.h so that it now works correctly (wrong parameter types) + * - Updated RNDIS demo - notification endpoint is no longer blocking so that it works with faulty Linux RNDIS + * implementations (where the notification endpoint is ignored in favour of polling the control endpoint) + * - Fixed incorrect Vendor Description string return size in RNDIS demo for the OID_GEN_VENDOR_DESCRIPTION OID token + * - Added very basic TCP/IP stack and HTTP/TELNET servers to RNDIS demo + * - Fixed DFU bootloader exit causing programming software to complain about failed writes + * - Fixed DFU bootloader EEPROM programming mode wiping first flash page + * - Fixed Clear/Set Feature device standard request processing code (fixing MassStorage demo in the process) + * - Added support for the ATMEGA16U4 AVR microcontroller + * - Library licence changed from LGPLv3 to MIT license + * + * + * \section Sec_ChangeLog151 Version 1.5.1 - Released 31st July, 2008 + * + * - Changed host demos to enable the host function task on the firing of the USB_DeviceEnumerationComplete event + * rather than the USB_DeviceAttached event + * - HID Usage Stack now forcefully cleared after an IN/OUT/FEATURE item has been completely processed to remove + * any referenced but not created usages + * - Changed USB_INT_DisableAllInterrupts() and USB_INT_ClearAllInterrupts(), USB_Host_GetNextDescriptorOfType(), + * USB_Host_GetNextDescriptorOfTypeBefore(), USB_Host_GetNextDescriptorOfTypeAfter() to normal functions (from inline) + * - Fixed USBtoSerial demo not sending data, only receiving + * - Fixed main makefile to make all by default, fixed MagStripe directory case to prevent case-sensitive path problems + * - ConfigDescriptor functions made normal, instead of static inline + * - Pipe/Endpoint *_Ignore_* functions changed to *_Discard_*, old names still present as aliases + * - Fixed ENDPOINT_MAX_SIZE define to be correct on limited USB controller AVRs + * - Changed endpoint and pipe size translation routines to use previous IF/ELSE IF cascade code, new algorithmic + * approach was buggy and caused problems + * - Bootloaders now compile with -fno-inline-small-functions option to reduce code size + * - Audio demos now use correct endpoint sizes for full and limited controller USB AVRs, double banking in all cases + * to be in line with the specification (isochronous endpoints MUST be double banked) + * - Added Interface Association descriptor to StdDescriptors.h, based on the relevant USB2.0 ECN + * - Fixed MIDI demo, corrected Audio Streaming descriptor to follow the MIDI-specific AS structure + * - Fixed HID class demo descriptors so that the HID interface's protocol is 0x00 (required for non-boot protocol HID + * devices) to prevent problems on hosts expecting the boot protocol functions to be supported + * - Added read/write control stream functions to Endpoint.h + * - Fixed AudioOut demo not setting port pins to inputs on USB disconnect properly + * - Added RNDISEthernet demo application + * + * + * \section Sec_ChangeLog150 Version 1.5.0 - Released 10 June, 2008 + * + * - Fixed MIDI demo, now correctly waits for the endpoint to be ready between multiple note messages + * - Added CDC Host demo application + * - Added KeyboardFullInt demo application + * - Endpoint and Pipe creation routines now mask endpoint/pipe size with the size mask, to remove transaction + * size bits not required for the routines (improves compatibility with devices) + * - Fixed AudioInput demo - now correctly sends sampled audio to the host PC + * - Fixed AudioOutput demo oncemore -- apparently Windows requires endpoint packets to be >=192 bytes + * - Shrunk round-robbin scheduler code slightly via the use of struct pointers rather than array indexes + * - Fixed off-by-one error when determining if the Usage Stack is full inside the HID Report parser + * - Renamed Magstripe.h to MagstripeHW.h and moved driver out of the library and into the MagStripe demo folder + * - Added preprocessor checks to enable C linkage on the library components when used with a C++ compiler + * - Added Still Image Host demo application + * - The USB device task now restores the previously selected endpoint, allowing control requests to be transparently + * handled via interrupts while other endpoints are serviced through polling + * - Fixed device signature being sent in reverse order in the CDC bootloader + * - Host demos now have a seperate ConfigDescriptor.c/.h file for configuration descriptor processing + * - HostWithParser demos now have a seperate HIDReport.c/.h file for HID report processing and dumping + * - Removed non-mandatory commands from MassStorage demo to save space, fixed SENSE ResponseCode value + * - CDC demos now send empty packets after sending a full one to prevent buffering issues on the host + * - Updated demo descriptors to use VID/PID values donated by Atmel + * - Added DoxyGen documentation to the source files + * - Fixed Serial_IsCharRecieved() definition, was previously reversed + * - Removed seperate USB_Descriptor_Language_t descriptor, USB_Descriptor_String_t is used instead + * - Removed unused Device Qualifier descriptor structure + * - Renamed the USB_CreateEndpoints event to the more appropriate USB_ConfigurationChanged + * - Fixed MassStorageHost demo reading in the block data in reverse + * - Removed outdated typedefs in StdRequestType.h, superceeded by the macro masks + * - Corrected OTG.h is now included when the AVR supports both Host and Device modes, for creating OTG products + * - USB_DeviceEnumerationComplete event is now also fired when in device mode and the host has finished its enumeration + * - Interrupt driven demos now properly restore previously selected endpoint when ISR is complete + * - USB_HOST_TIMEOUT_MS is now overridable in the user project makefile to a custom fixed timeout value + * - Renamed USB_Host_SOFGeneration_* macros to more friendly USB_Host_SuspendBus(), USB_Host_ResumeBus() + * and USB_Host_IsBusSuspended() + * - Renamed *_*_Is* macros to *_Is* to make all flag checking macros consistant, Pipe_SetInterruptFreq() is now + * Pipe_SetInterruptPeriod() to use the correct terminology + * - UnicodeString member of USB_Descriptor_String_t struct changed to an ordinary int array type, so that the GCC + * Unicode strings (prefixed with an L before the opening quotation mark) can be used instead of explicit arrays + * of ASCII characters + * - Fixed Endpoint/Pipes being configured incorrectly if the maximum endpoint/pipe size for the selected USB AVR + * model was given as the bank size + * - HID device demos now use a true raw array for the HID report descriptor rather than a struct wrapped array + * - Added VERSION_BCD() macro, fixed reported HID and USB version numbers in demo descriptors + * - Cleaned up GetDescriptor device chapter 9 handler function + * - Added GET_REPORT class specific request to HID demos to make them complaint to the HID class + * - Cleaned up setting of USB_IsInitialized and USB_IsConnected values to only when needed + * - Removed Atomic.c and ISRMacro.h; the library was already only compatible with recent avr-lib-c for other reasons + * - All demos and library functions now use USB standardized names for the USB data (bRequest, wLength, etc.) + * - Added USE_NONSTANDARD_DESCRIPTOR_NAMES token to switch back to the non-standard descriptor element names + * + * + * \section Sec_ChangeLog141 Version 1.4.1 - Released 5 May, 2008 + * + * - Enhanced KeyboardWithParser demo, now prints out pressed alphanumeric characters like the standard demo + * - Fixed MassStorage demo, read/writes using non mode-10 commands now work correctly + * - Corrected version number in Version.h + * + * + * \section Sec_ChangeLog140 Version 1.4.0 - Released 5 May, 2008 + * + * - Added HID Report Parser API to the library + * - Added Mouse and Keyboard host demo applications, using the new HID report parser engine + * - Added MouseFullInt demo, which demonstrates a fully interrupt (including control requests) mouse device + * - Fixed incorrect length value in the audio control descriptor of the AudioOutput and AudioInput demos + * - Added MIDI device demo application to the library + * - Fixed problem preventing USB devices from being resumed from a suspended state + * - Added new CDC class bootloader to the library, based on the AVR109 bootloader protocol + * - Added header to each demo application indicating the mode, class, subclass, standards used and supported speed + * - Functions expecting endpoint/pipe numbers are no longer automatically masked against ENDPOINT_EPNUM_MASK or + * PIPE_PIPENUM_MASK - this should be manually added to code which requires it + * - Fixed DFU class bootloader - corrected frequency of flash page writes, greatly reducing programming time + * - Renamed AVR_HOST_GetDeviceConfigDescriptor() to USB_Host_GetDeviceConfigDescriptor() and AVR_HOST_GetNextDescriptor() + * to USB_Host_GetNextDescriptor() + * - Added new USB_Host_GetNextDescriptorOfTypeBefore() and USB_Host_GetNextDescriptorOfTypeAfter() routines + * - Moved configuration descriptor routines to MyUSB/Drivers/USB/Class/, new accompanying ConfigDescriptors.c file + * - Added new configuration descriptor comparator API for more powerful descriptor parsing, updated host demos to use the + * new comparator API + * - Fixed MassStorageHost demo capacity printout, and changed data read/write mode from little-endian to the correct + * big-endian for SCSI devices + * - Fixed macro/function naming consistancy; USB_HOST is now USB_Host, USB_DEV is now USB_Device + * - Added better error reporting to host demos + * - Added 10 microsecond delay after addressing devices in host mode, to prevent control stalls + * + * + * \section Sec_ChangeLog132 Version 1.3.2 - Released April 1st, 2008 + * + * - Added call to ReconfigureUSART() in USBtoSerial SetLineCoding request, so that baud rate changes + * are reflected in the hardware + * - Fixed CDC and USBtoSerial demos - Stream commands do not work for control endpoints, and the + * GetLineCoding request had an incorrect RequestType mask preventing it from being processed + * - Improved reliability of the USBtoSerial demo, adding a busy wait while the buffer is full + * - Device control endpoint size is now determined from the device's descriptors rather than being fixed + * - Seperated out SPI code into new SPI driver in AT90USBXXX driver directory + * - Bootloader now returns correct PID for the selected USB AVR model, not just the AT90USB128X PID + * - Added support for the RZUSBSTICK board + * - Bicolour driver removed in favour of generic LEDs driver + * - Added support for the ATMEGA32U4 AVR + * - Added MANUAL_PLL_CONTROL compile time option to prevent the USB library from manipulating the PLL + * + * + * \section Sec_ChangeLog131 Version 1.3.1 - Released March 19th 2008 + * + * - Fixed USB to Serial demo - class value in the descriptors was incorrect + * - Control endpoint size changed from 64 bytes to 8 bytes to save on USB FIFO RAM and to allow low + * speed mode devices to enumerate properly + * - USB to Serial demo data endpoints changed to dual-banked 16 byte to allow the demo to work + * on USB AVRs with limited USB FIFO RAM + * - Changed demo endpoint numbers to use endpoints 3 and 4 for double banking, to allow limited + * USB device controller AVRs (AT90USB162, AT90USB82) to function correctly + * - Updated Audio Out demo to use timer 1 for AVRs lacking a timer 3 for the PWM output + * - Fixed incorrect USB_DEV_OPT_HIGHSPEED entry in the Mass Storage device demo makefile + * - Optimized Mass Storage demo for a little extra transfer speed + * - Added LED indicators to the Keyboard demo for Caps Lock, Num Lock and Scroll Lock + * - Added Endpoint_Read_Stream, Endpoint_Write_Stream, Pipe_Read_Stream and Pipe_Write_Stream functions + * (including Big and Little Endian variants) + * - Made Dataflash functions inline for speed, removed now empty Dataflash.c driver file + * - Added new SetSystemClockPrescaler() macro - thanks to Joerg Wunsch + * - Fixed Endpoint_ClearStall() to function correctly on full USB controller AVRs (AT90USBXXX6/7) + * - Endpoint_Setup_In_Clear() and Endpoint_Setup_Out_Clear() no longer set FIFOCON, in line with the + * directives in the datasheet + * - Fixed PLL prescaler defines for all AVR models and frequencies + * - Fixed ENDPOINT_INT_IN and ENDPOINT_INT_OUT definitions + * - Added interrupt driven keyboard and mouse device demos + * - Combined USB_Device_ClearFeature and USB_Device_SetFeature requests into a single routine for code + * size savings + * - Added missing Pipe_GetCurrentPipe() macro to Pipe.h + * + * + * \section Sec_ChangeLog130 Version 1.3.0 - Released March 7th 2008 + * + * - Unneccesary control endpoint config removed from device mode + * - Fixed device standard request interpreter accidentally processing some class-specific requests + * - Added USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS compile time options to instruct the library + * to use descriptors stored in RAM or EEPROM rather than flash memory + * - All demos now disable watchdog on startup, in case it has been enabled by fuses or the bootloader + * - USB_DEV_OPT_LOWSPEED option now works correctly + * - Added ability to set the USB options statically for a binary size reduction via the USE_STATIC_OPTIONS + * compile time define + * - USB_Init no longer takes a Mode parameter if compiled for a USB device with no host mode option, or + * if forced to a particular mode via the USB_HOST_ONLY or USB_DEVICE_ONLY compile time options + * - USB_Init no longer takes an Options parameter if options statically configured by USE_STATIC_OPTIONS + * - Endpoint_Ignore_* and Pipe_Ignore_* made smaller by making the dummy variable non-volatile so that the + * compiler can throw away the result more efficiently + * - Added in an optional GroupID value to each scheduler entry, so that groups of tasks can once again be + * controlled by the new Scheduler_SetGroupTaskMode() routine + * - Added support for AT90USB162 and AT90USB82 AVR models + * - Added support for the STK525 and STK526 boards + * - Added support for custom board drivers to be supplied by selecting the board type as BOARD_USER, and + * placing board drivers in {Application Directory}/Board/ + * - PLL is now stopped and USB clock is frozen when detatched from host in device mode, to save power + * - Joystick defines are now in synch with the schematics - orientation will be rotated for the USBKEY + * - Fixed USB_DEV_IsUSBSuspended() - now checks the correct register + * - Fixed data transfers to devices when in host mode + * - Renamed USB_DEV_OPT_HIGHSPEED to USB_DEV_OPT_FULLSPEED and USB_HOST_IsDeviceHighSpeed() to + * USB_HOST_IsDeviceFullSpeed() to be in line with the official USB speed names (to avoid confusion with + * the real high speed mode, which is unavailable on the USB AVRs) + * + * + * \section Sec_ChangeLog120 Version 1.2.0 - Released February 4th, 2008 + * + * - Added USB_DeviceEnumerationComplete event for host mode + * - Added new Scheduler_Init routine to preprepare the scheduler, so that tasks can be started and + * stopped before the scheduler has been started (via Scheduler_Start) + * - Connection events in both Device and Host mode are now interrupt-driven, allowing the USB management + * task to be stopped when the USB is not connected to a host or device + * - All demos updated to stop the USB task when not in use via the appropriate USB events + * - Mass Storage Host demo application updated to function correctly with all USB flash disks + * - Mass Storage Host demo application now prints out the capacity and number of LUNs in the attached + * device, and prints the first block as hexadecimal numbers rather than ASCII characters + * - Endpoint and Pipe clearing routines now clear the Endpoint/Pipe interrupt and status flags + * - Shifted error handling code in the host enum state machine to a single block, to reduce code complexity + * - Added in DESCRIPTOR_TYPE, DESCRIPTOR_SIZE and DESCRIPTOR_CAST macros to make config descriptor processing + * clearer in USB hosts and DESCRIPTOR_ADDRESS for convenience in USB devices + * - Added in alloca macro to common.h, in case the user is using an old version of avr-lib-c missing the macro + * + * + * \section Sec_ChangeLog130 Version 1.1.0 - Released January 25th 2008 + * + * - Fixed DCONNI interrupt being enabled accidentally after a USB reset + * - Fixed DDISCI interrupt not being disabled when a device is not connected + * - Added workaround for powerless pullup devices causing false disconnect interrupts + * - Added USB_DeviceEnumerationFailed event for Host mode + * - AVR_HOST_GetDeviceConfigDescriptor routine no longer modifies ConfigSizePtr if a valid buffer + * pointer is passed + * - Added ALLOCABLE_BYTES to DynAlloc, and added code to make the size of key storage variables + * dependant on size of memory parameters passed in via the user project's makefile + * - Fixed incorrect device reset routine being called in USBTask + * - Devices which do not connect within the standard 300mS are now supported + * - Removed incorrect ATTR_PURE from Scheduler_SetTaskMode(), which was preventing tasks from being + * started/stopped, as well as USB_InitTaskPointer(), which was breaking dual device/host USB projects + * - Changed scheduler to use the task name rather than IDs for setting the task mode, eliminating the + * need to have a task ID list + * - ID transistion interrupt now raises the appropriate device/host disconnect event if device attached + * - Fixed double VBUS change (and VBUS -) event when detatching in device mode + * - Added ability to disable ANSI terminal codes by the defining of DISABLE_TERMINAL_CODES in makefile + * - Removed return from ConfigurePipe and ConfigureEndpoint functions - use Pipe_IsConfigured() and + * Endpoint_IsConfigured() after calling the config functions to determine success + */ \ No newline at end of file diff --git a/LUFA/Common/BoardTypes.h b/LUFA/Common/BoardTypes.h new file mode 100644 index 0000000000..d4a36550ee --- /dev/null +++ b/LUFA/Common/BoardTypes.h @@ -0,0 +1,72 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file contains constants which can be passed to the compiler (via setting the macro BOARD) in the + * user project makefile using the -D option to configure the library board-specific drivers. + * + * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's + * functionality. + */ + +#ifndef __BOARDTYPES_H__ +#define __BOARDTYPES_H__ + + /* Preprocessor Checks: */ + #if !defined(__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 USBKEY specific board drivers, including Dataflash, Joystick and LED drivers. */ + #define BOARD_USBKEY 0 + + /** Selects the STK525 specific board drivers, including Dataflash, Joystick and LED drivers. */ + #define BOARD_STK525 1 + + /** Selects the STK526 specific board drivers, including Dataflash, Joystick and LED drivers. */ + #define BOARD_STK526 2 + + /** Selects the RZUSBSTICK specific board drivers, including the driver for the boards LEDs. */ + #define BOARD_RZUSBSTICK 3 + + /** Selects the ATAVRUSBRF01 specific board drivers, including the driver for the board LEDs. */ + #define BOARD_ATAVRUSBRF01 4 + + /** Selects the user-defined board drivers, which should be placed in the user project's folder + * under a directory named /Board/. Each board driver should be named identically to the LUFA + * master board driver (i.e., driver in the LUFA/Drivers/Board director) so that the library + * can correctly identify it. + */ + #define BOARD_USER 5 + +#endif diff --git a/LUFA/Common/ButtLoadTag.h b/LUFA/Common/ButtLoadTag.h new file mode 100644 index 0000000000..54fab0f02f --- /dev/null +++ b/LUFA/Common/ButtLoadTag.h @@ -0,0 +1,77 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file contains macros for the embedding of compile-time strings into the resultant project binary for + * identification purposes. It is designed to prefix "tags" with the magic string of "@(#)" so that the tags + * can easily be identified in the binary data. + * + * These tags are compatible with the ButtLoad project at http://www.fourwalledcubicle.com/ButtLoad.php . + */ + +#ifndef __BUTTLOADTAG_H__ +#define __BUTTLOADTAG_H__ + + /* Includes: */ + #include + #include + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Creates a new tag in the resultant binary, containing the specified data array. The macro id + * parameter is only for identification purposes (so that the tag data can be referenced in code) + * and is not visible in the compiled binary. + */ + #define BUTTLOADTAG(id, data) const struct ButtLoadTagData BUTTTAG_##id \ + PROGMEM __attribute__((used, externally_visible)) = \ + {MagicString: BT_TAGHEADER, TagData: data} + + /** Macro for retrieving a reference to the specified tag's contents. The tag data is located in + * the program memory (FLASH) space, and so must be read out with the macros in avr-libc which + * deal with embedded data. + */ + #define BUTTLOADTAG_DATA(id) BUTTTAG_##id.TagData + + /* Structures: */ + /** Structure for ButtLoad compatible binary tags. */ + struct ButtLoadTagData + { + char MagicString[4]; /**< Magic tag header, containing the string "@(#)". */ + char TagData[]; /**< Tag contents as a char array. */ + }; + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define BT_TAGHEADER {'@','(','#',')'} + #endif + +#endif diff --git a/LUFA/Common/Common.h b/LUFA/Common/Common.h new file mode 100644 index 0000000000..97e9ce9318 --- /dev/null +++ b/LUFA/Common/Common.h @@ -0,0 +1,171 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file contains macros which are common to all library elements, and which may be useful in user code. It + * also includes other common headees, such as Atomic.h, FunctionAttributes.h and BoardTypes.h. + */ + +#ifndef __COMMON_H__ +#define __COMMON_H__ + + /* Includes: */ + #include + #include + #include + + #include "FunctionAttributes.h" + #include "BoardTypes.h" + + #include + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Macro for encasing other multi-statment macros. This should be used along with an opening brace + * before the start of any multi-statement macro, so that the macros contents as a whole are treated + * as a discreete block and not as a list of seperate statements which may cause problems when used as + * a block (such as inline IF statments). + */ + #define MACROS do + + /** Macro for encasing other multi-statment macros. This should be used along with a preceeding closing + * brace at the end of any multi-statement macro, so that the macros contents as a whole are treated + * as a discreete block and not as a list of seperate statements which may cause problems when used as + * a block (such as inline IF statments). + */ + #define MACROE while (0) + + /** Defines a volatile NOP statment which cannot be optimized out by the compiler, and thus can always + * be set as a breakpoint in the resulting code. Useful for debugging purposes, where the optimizer + * removes/reorders code to the point where break points cannot reliably be set. + */ + #define JTAG_DEBUG_POINT() asm volatile ("NOP" ::) + + /** Defines an explicit JTAG break point in the resulting binary via the ASM BREAK statment. When + * a JTAG is used, this causes the program execution to halt when reached until manually resumed. */ + #define JTAG_DEBUG_BREAK() asm volatile ("BREAK" ::) + + /** Macro for testing condition "x" and breaking via JTAG_DEBUG_BREAK() if the condition is false. */ + #define JTAG_DEBUG_ASSERT(x) MACROS{ if (!(x)) { JTAG_DEBUG_BREAK(); } }MACROE + + /** Macro for testing condition "x" and writing debug data to the serial stream if false. As a + * prerequisite for this macro, the serial stream should be configured via the Serial_Stream driver. + * + * The serial output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion + * {x} failed." + */ + #define SERIAL_STREAM_ASSERT(x) MACROS{ if (!(x)) { printf_P(PSTR("%s: Function \"%s\", Line %d: " \ + "Assertion \"%s\" failed.\r\n"), \ + __FILE__, __func__, __LINE__, #x); \ + } }MACROE + + /* Inline Functions: */ + /** Function for reliably setting the AVR's system clock prescaler, using inline assembly. This function + * is guaranteed to operate reliably regardless of optimization setting or other compile time options. + * + * \param PrescalerMask The mask of the new prescaler setting for CLKPR + */ + static inline void SetSystemClockPrescaler(uint8_t PrescalerMask) + { + uint8_t tmp = (1 << CLKPCE); + __asm__ __volatile__ ( + "in __tmp_reg__,__SREG__" "\n\t" + "cli" "\n\t" + "sts %1, %0" "\n\t" + "sts %1, %2" "\n\t" + "out __SREG__, __tmp_reg__" + : /* no outputs */ + : "d" (tmp), + "M" (_SFR_MEM_ADDR(CLKPR)), + "d" (PrescalerMask) + : "r0"); + } + + /** Function to reverse the individual bits in a byte - i.e. bit 7 is moved to bit 0, bit 6 to bit 1, + * etc. + * + * \param Byte Byte of data whose bits are to be reversed + */ + static inline uint8_t BitReverse(uint8_t Byte) ATTR_WARN_UNUSED_RESULT ATTR_CONST; + static inline uint8_t BitReverse(uint8_t Byte) + { + Byte = (((Byte & 0xF0) >> 4) | ((Byte & 0x0F) << 4)); + Byte = (((Byte & 0xCC) >> 2) | ((Byte & 0x33) << 2)); + Byte = (((Byte & 0xAA) >> 1) | ((Byte & 0x55) << 1)); + + return Byte; + } + + /** Function to reverse the byte ordering of the individual bytes in a 16 bit number. + * + * \param Word Word of data whose bytes are to be swapped + */ + static inline uint16_t SwapEndian_16(uint16_t Word) ATTR_WARN_UNUSED_RESULT ATTR_CONST; + static inline uint16_t SwapEndian_16(uint16_t Word) + { + return ((Word >> 8) | (Word << 8)); + } + + /** Function to reverse the byte ordering of the individual bytes in a 32 bit number. + * + * \param DWord Double word of data whose bytes are to be swapped + */ + static inline uint32_t SwapEndian_32(uint32_t DWord) ATTR_WARN_UNUSED_RESULT ATTR_CONST; + static inline uint32_t SwapEndian_32(uint32_t DWord) + { + return (((DWord & 0xFF000000) >> 24) | + ((DWord & 0x00FF0000) >> 8) | + ((DWord & 0x0000FF00) << 8) | + ((DWord & 0x000000FF) << 24)); + } + + /** Function to reverse the byte ordering of the individual bytes in a n byte number. + * + * \param Data Pointer to a number containing an even number of bytes to be reversed + * \param Bytes Length of the data in bytes + */ + static inline void SwapEndian_n(uint8_t* Data, uint8_t Bytes); + static inline void SwapEndian_n(uint8_t* Data, uint8_t Bytes) + { + uint8_t Temp; + + while (Bytes) + { + Temp = *Data; + *Data = *(Data + Bytes - 1); + *(Data + Bytes) = Temp; + + Data++; + Bytes -= 2; + } + } + +#endif diff --git a/LUFA/Common/FunctionAttributes.h b/LUFA/Common/FunctionAttributes.h new file mode 100644 index 0000000000..16503bb551 --- /dev/null +++ b/LUFA/Common/FunctionAttributes.h @@ -0,0 +1,110 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file contains macros for applying GCC specific attributes to functions to control various optimizer + * and code generation features of the compiler. Attributes may be placed in the function prototype in any + * order, and multiple attributes can be specified for a single function via a space seperated list. + * + * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's + * functionality. + */ + +#ifndef __FUNCATTR_H__ +#define __FUNCATTR_H__ + + /* Preprocessor Checks: */ + #if !defined(__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: */ + /** Indicates to the compiler that the function can not ever return, so that any stack restoring or + * return code may be ommited by the compiler in the resulting binary. + */ + #define ATTR_NO_RETURN __attribute__ ((noreturn)) + + /** Places the function in one of the initilization sections, which execute before the main function + * of the application. The init function number can be specified as "x", as an integer. Refer to the + * avr-libc manual for more information on the initialization sections. + */ + #define ATTR_INIT_SECTION(x) __attribute__ ((naked, section (".init" #x ))) + + /** Indicates that the function returns a value which should not be ignored by the user code. When + * applied, any ignored return value from calling the function will produce a compiler warning. + */ + #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) + + /** Indicates that the specified parameters of the function are pointers which should never be NULL. + * When applied as a 1-based comma seperated list the compiler will emmit a warning if the specified + * parameters are known at compiler time to be NULL at the point of calling the function. + */ + #define ATTR_NON_NULL_PTR_ARG(...) __attribute__ ((nonnull (__VA_ARGS__))) + + /** Removes any preample or postample from the function. When used, the function will not have any + * register or stack saving code. This should be used with caution, and when used the programmer + * is responsible for maintaining stack and register integrity. + */ + #define ATTR_NAKED __attribute__ ((naked)) + + /** Prevents the compiler from considering a specified function for inlining. When applied, the given + * function will not be inlined under any circumstances. + */ + #define ATTR_NOINLINE __attribute__ ((noinline)) + + /** Forces the compiler to inline the specified function. When applied, the given function will be + * inlined under all circumstances. + */ + #define ATTR_ALWAYSINLINE __attribute__ ((always_inline)) + + /** Indicates that the specified function is pure, in that it has no side-effects other than global + * or parameter variable access. + */ + #define ATTR_PURE __attribute__ ((pure)) + + /** Indicates that the specified function is constant, in that it has no side effects other than + * parameter access. + */ + #define ATTR_CONST __attribute__ ((const)) + + /** Marks a given function as deprecated, which produces a warning if the function is called. */ + #define ATTR_DEPRECATED __attribute__ ((deprecated)) + + /** Marks a function as a weak reference, which can be overridden by other functions with an + * identical name (in which case the weak reference is discarded at link time). + */ + #define ATTR_WEAK __attribute__ ((weak)) + + /** Marks a function as an alias for another function of name "x". */ + #define ATTR_ALIAS(x) __attribute__ ((alias( #x ))) + +#endif diff --git a/LUFA/CompileTimeTokens.txt b/LUFA/CompileTimeTokens.txt new file mode 100644 index 0000000000..196132b956 --- /dev/null +++ b/LUFA/CompileTimeTokens.txt @@ -0,0 +1,167 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \page TokenSummary Summary of Compile Tokens + * + * The following lists all the possible tokens which can be defined in a project makefile, and passed to the + * compiler via the -D switch, to alter the LUFA library code. These tokens may alter the library behaviour, + * or remove features unused by a given application in order to save flash space. + * + * \section Sec_SummaryNonUSBTokens Non USB Related Tokens + * This section describes compile tokens which affect non-USB sections of the LUFA library. + * + * DISABLE_TERMINAL_CODES - TerminalCodes.h \n + * If an application contains ANSI terminal control codes listed in TerminalCodes.h, it might be desired to remove them + * at compile time for use with a terminal which is non-ANSI control code aware, without modifying the source code. If + * this token is defined, all ANSI control codes in the application code from the TerminalCodes.h header are removed from + * the source code at compile time. + * + * NUM_BLOCKS - DynAlloc.h \n + * Sets the number of allocable blocks in the psudo-heap of the dynamic memory allocation driver. This should be + * defined as a constant larger than zero. + * + * BLOCK_SIZE - DynAlloc.h \n + * Sets the size of each allocable block in the psudo-heap of the dynamic memory allocation driver. This should be + * defined as a constant larger than zero. + * + * NUM_HANDLES - DynAlloc.h \n + * Sets the maximum number of managed memory handles which can be handed out by the dynamic memory allocation driver + * simultaneously, before a handle (and its associated allocated memory) must be freed. + * + * \section Sec_SummaryUSBClassTokens USB Class Driver Related Tokens + * This section describes compile tokens which affect USB class-specific drivers in the LUFA library. + * + * HID_ENABLE_FEATURE_PROCESSING - HIDParser.h \n + * Define this token to enable the processing of FEATURE HID report items, if any, into the processed HID structure. + * By default FEATURE items (which are device features settable by the host but not directly visible by the user) are + * skipped when processing a device HID report. + * + * HID_INCLUDE_CONSTANT_DATA_ITEMS - HIDParser.h \n + * By default, constant data items (usually used as spacers to align seperate report items to a byte or word boundary) + * in the HID report are skipped during report processing. It is highly unusual for an application to make any use of + * constant data items (as they do not carry any useful data and only occupy limited RAM) however if required defining + * this switch will put constant data items into the processed HID report structure. + * + * HID_STATETABLE_STACK_DEPTH - HIDParser.h \n + * HID reports may contain PUSH and POP elements, to store and retrieve the current HID state table onto a stack. This + * allows for reports to save the state table before modifying it slightly for a data item, and then restore the previous + * state table in a compact manner. This token may be defined to a non-zero value to give the maximum depth of the state + * table stack. If not defined, this defaults to the value indicated in the HID.h file documentation. + * + * HID_USAGE_STACK_DEPTH - HIDParser.h \n + * HID reports generally contain many USAGE elements, which are assigned to INPUT, OUTPUT and FEATURE items in succession + * when multiple items are defined at once (via REPORT COUNT elements). This allows for several items to be defined with + * different usages in a compact manner. This token may be defined to a non-zero value to set the maximum depth of the + * usage stack, indicating the maximum number of USAGE items which can be stored tempoarily until the next INPUT, OUTPUT + * and FEATURE item. If not defined, this defaults to the value indicated in the HID.h file documentation. + * + * HID_MAX_COLLECTIONS - HIDParser.h \n + * HID reports generally contain several COLLECTION elements, used to group related data items together. Collection information + * is stored seperately in the processed usage structure (and referred to by the data elements in the structure) to save space. + * This token may be defined to a non-zero value to set the maximum number of COLLECTION items which can be processed by the + * parser into the resultant processed report structure. If not defined, this defaults to the value indicated in the HID.h file + * documentation. + * + * HID_MAX_REPORTITEMS - HIDParser.h \n + * All HID reports contain one or more INPUT, OUTPUT and/or FEATURE items describing the data which can be sent to and from the HID + * device. Each item has associated usages, bit offsets in the item reports and other associated data indicating the manner in which + * the report data should be interpreted by the host. This token may be defined to a non-zero value to set the maximum number of + * data elements which can be stored in the processed HID report strucuture, including INPUT, OUTPUT and (if enabled) FEATURE items. + * If a item has a multiple count (i.e. a REPORT COUNT of more than 1), each item in the report count is placed seperately in the + * processed HID report table. If not defined, this defaults to the value indicated in the HID.h file documentation. + * + * \section Sec_SummaryUSBTokens USB Driver Related Tokens + * This section describes compile tokens which affect USB driver stack as a whole in the LUFA library. + * + * USE_RAM_DESCRIPTORS - StdDescriptors.h \n + * Define this token to indicate to the USB driver that device descriptors are stored in RAM, rather than the default of + * the AVR's flash. RAM descriptors may be desirable in applications where speed or minimizing flash usage is more important + * than RAM usage, or applications where the descriptors need to be modified at runtime. + * + * USE_EEPROM_DESCRIPTORS - StdDescriptors.h \n + * Similar to USE_RAM_DESCRIPTORS, but descriptors are stored in the AVR's EEPROM memory rather than RAM. + * + * USE_NONSTANDARD_DESCRIPTOR_NAMES - StdDescriptors.h \n + * The USB 2.0 standard gives some rather obscure names for the elements in the standard descriptor types (device, configuration, + * string, endpoint, etc.). By default the LUFA library uses these names in its predefined descriptor structure types for + * compatibility. If this token is defined, the structure element names are switched to the LUFA-specific but more descriptive + * names documented in the StdDescriptors.h source file. + * + * FIXED_CONTROL_ENDPOINT_SIZE - Endpoint.h \n + * By default, the library determines the size of the control endpoint (when in device mode) by reading the device descriptor. + * Normally this reduces the amount of configuration required for the library, allows the value to change dynamically (if + * descriptors are stored in EEPROM or RAM rather than flash memory) and reduces code maintenance. However, this token can be + * defined to a non-zero value instead to give the size in bytes of the control endpoint, to reduce the size of the compiled + * binary at the expense of flexibility. + * + * STATIC_ENDPOINT_CONFIGURATION - Endpoint.h \n + * By default, the endpoint configuration routine is designed to accept dynamic inputs, so that the endpoints can be configured + * using variable values known only at runtime. This allows for a great deal of flexibility, however uses a small amount of binary + * space which may be wasted if all endpoint configurations are static and known at compile time. Define this token via the -D switch + * to optimize the endpoint configuration routine for constant inputs, to reduce the size of the compiled binary at the expense of + * flexibility. Note that with this option dynamic values may still be used, but will result in many times more code to be generated than + * if the option was disabled. This is designed to be used only if the FIXED_CONTROL_ENDPOINT_SIZE option is also used. + * + * USE_SINGLE_DEVICE_CONFIGURATION - DevChapter9.h \n + * By default, the library determines the number of configurations a USB device supports by reading the device descriptor. This reduces + * the amount of configuration required to set up the library, and allows the value to change dynamically (if descriptors are stored in + * EEPROM or RAM rather than flash memory) and reduces code maintenance. However, many USB device projects use only a single configuration. + * Defining this token enables single-configuration mode, reducing the compiled size of the binary at the expense of flexibility. + * + * NO_CLEARSET_FEATURE_REQUEST - DevChapter9.h \n + * In some limited USB device applications, the Get Feature and Set Feature requests are not used - this is when the device does not have + * device level features (such as remote wakeup) nor any data endpoints beyond the mandatory control endpoint. In such limited situations, + * this token may be defined to remove the handling of the Get Feature and Set Feature Chapter 9 requests to save space. Generally, this + * is usually only useful in (some) bootloaders. + * + * NO_STREAM_CALLBACKS - Endpoint.h, Pipe.h \n + * Both the endpoint and the pipe driver code contains stream functions, allowing for arrays of data to be sent to or from the + * host easily via a single function call (rather than complex routines worrying about sending full packets, waiting for the endpoint/ + * pipe to become ready, etc.). By default, these stream functions require a callback function which is executed after each byte processed, + * allowing for early-aborts of stream transfers by the application. If callbacks are not required in an application, they can be removed + * by defining this token, reducing the compiled binary size. When removed, the stream functions no longer accept a callback function as + * a parameter. + * + * USB_HOST_TIMEOUT_MS - Host.h \n + * When a control transfer is initiated in host mode to an attached device, a timeout is used to abort the transfer if the attached + * device fails to respond within the timeout period. This token may be defined to a non-zero value to set the timeout period for + * control transfers, specified in milliseconds. If not defined, the default value specified in Host.h is used instead. + * + * HOST_DEVICE_SETTLE_DELAY_MS - Host.h \n + * Some devices require a delay of up to 5 seconds after they are connected to VBUS before the enumeration process can be started, or + * they will fail to enumerate correctly. By placing a delay before the enumeration process, it can be ensured that the bus has settled + * back to a known idle state before communications occur with the device. This token may be defined to a non-zero value to set the + * device settle period, specified in milliseconds. If not defined, the default value specified in Host.h is used instead. + * + * USE_STATIC_OPTIONS - LowLevel.h \n + * By default, the USB_Init() function accepts dynamic options at runtime to alter the library behaviour, including whether the USB pad + * voltage regulator is enabled, and the device speed when in device mode. By defining this token to a mask comprised of the USB options + * mask defines usually passed as the Options parameter to USB_Init(), the resulting compiled binary can be decreased in size by removing + * the dynamic options code, and replacing it with the statically set options. When defined, the USB_Init() function no longer accepts an + * Options parameter. + * + * USB_DEVICE_ONLY - LowLevel.h \n + * For the USB AVR models supporting both device and host USB modes, the USB_Init() function contains a Mode parameter which specifies the + * mode the library should be initialized to. If only device mode is required, the code for USB host mode can be removed from the binary to + * save space. When defined, the USB_Init() function no longer accepts a Mode parameter. This define is irrelevent on smaller USB AVRs which + * do not support host mode. + * + * USB_HOST_ONLY - LowLevel.h \n + * Same as USB_DEVICE_ONLY, except the library is fixed to USB host mode rather than USB device mode. Not available on some USB AVR models. + * + * USB_STREAM_TIMEOUT_MS - LowLevel.h \n + * When endpoint and/or pipe stream functions are used, by default there is a timeout between each transfer which the connected device or host + * must satisfy, or the stream function aborts the remaining data transfer. This token may be defined to a non-zero value to set the timeout + * period for stream transfers, specified in milliseconds. If not defined, the default value specified in LowLevel.h is used instead. + * + * NO_LIMITED_CONTROLLER_CONNECT - Events.h \n + * On the smaller USB AVRs, the USB controller lacks VBUS events to determine the physical connection state of the USB bus to a host. In lieu of + * VBUS events, the library attempts to determine the connection state via the bus suspension and wake up events instead. This however may be + * slightly inaccurate due to the possibility of the host suspending the bus while the device is still connected. If accurate connection status is + * required, the VBUS line of the USB connector should be routed to an AVR pin to detect its level, so that the USB_IsConnected global + * can be accurately set and the USB_Connect and USB_Disconnect events manually raised by the RAISE_EVENT macro. When defined, this token disables + * the library's auto-detection of the connection state by the aformentioned suspension and wake up events. + */ diff --git a/LUFA/DirectorySummaries.txt b/LUFA/DirectorySummaries.txt new file mode 100644 index 0000000000..1abf3d494d --- /dev/null +++ b/LUFA/DirectorySummaries.txt @@ -0,0 +1,119 @@ +/** \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. + */ + +/** \dir Common + * \brief Common library header files. + * + * This folder contains header files which are common to all parts of the LUFA library. They may be used freely in + * user applications. + * + * \dir MemoryAllocator + * \brief Auto-defragmenting dynamic memory allocation library. + * + * This folder contains a simple handle-based dynamic memory allocation library, capable of handing out memory in + * block chunks. As new memory is allocated, the library will defragment the already allocated memory to ensure + * optimal memory usage. It is not used within the LUFA library, and is provided as a convenience for user applications. + * + * \dir Scheduler + * \brief Simple round-robbin scheduler. + * + * This folder contains the simple LUFA round-robbin scheduler, provided as a convenience for user applications. It + * is very simple in design, and is intended to make code easier to read, rather than providing a complete RTOS kernel. + * + * \dir Drivers + * \brief Library hardware and software drivers. + * + * This folder contains all the library hardware and software drivers for each supported board and USB AVR + * microcontroller model. + * + * \dir Drivers/Misc + * \brief Miscellaneous driver files. + * + * This folder contains drivers for aspects other than the USB interface, board hardware or AVR peripherals. + * + * \dir Drivers/AT90USBXXX + * \brief USB AVR peripheral driver files. + * + * This folder contains drivers for several of the AVR internal peripherals such as the USART, compatible with + * all USB AVR models. + * + * \dir Drivers/AT90USBXXX/AT90USBXXX67 + * \brief AT90USBXXX6, AT90USBXXX7 and ATMEGAXXU4 AVR model peripheral driver files. Its original name is due to legacy + * reasons. + * + * This folder contains drivers for several of the AVR internal peripherals such as the USART, compatible only with + * the AT90USBXXX6, AT90USBXXX7 and ATMEGAXXU4 USB AVR models, such as the AT90USB1287. Its contents should not be + * included by the user application - the dispatch header file located in the parent AT90USBXXX directory should be used + * instead. + * + * \dir Drivers/USB + * \brief USB controller peripheral driver files. + * + * This folder contains the main header files required to implement the USB interface in the USB supporting AVR models. + * The header files contained directly in this folder should be included in the user application in order to gain USB + * functionality, and the appropriate C source files in the LowLevel and HighLevel driver folders added to the compile + * and link stages. + * + * \dir Drivers/USB/LowLevel + * \brief Low level USB driver files. + * + * This folder contains low level USB driver source files required to implement USB functionality on the USB AVR microcontrollers. + * + * \dir Drivers/USB/HighLevel + * \brief High level USB driver files. + * + * This folder contains high level USB driver source files required to implement USB functionality on the USB AVR microcontrollers. + * + * \dir Drivers/USB/Class + * \brief USB Class helper driver files. + * + * This folder contains drivers for implementing functionality of standardized USB classes. These are not used directly by the library, + * but provide a standard and library-maintained way of implementing functionality from some of the defined USB classes without extensive + * development effort. Is is recommended that these drivers be used where possible to reduce maintenance of user applications. + * + * \dir Drivers/Board + * \brief Board hardware driver files. + * + * This folder contains drivers for interfacing with the physical hardware on supported commercial boards, primarily from + * the Atmel corporation. Header files in this folder should be included in user applications requring the functionality of + * hardware placed on supported boards. + * + * \dir Drivers/Board/USBKEY + * \brief USBKEY board hardware driver files. + * + * This folder contains drivers for hardware on the Atmel USBKEY demonstration board. The header files in this folder should + * not be included directly in user applications; the similarly named dispatch header files located in the parent Board directory + * should be included instead. + * + * \dir Drivers/Board/STK526 + * \brief STK526 board hardware driver files. + * + * This folder contains drivers for hardware on the Atmel STK526 development board. The header files in this folder should + * not be included directly in user applications; the similarly named dispatch header files located in the parent Board directory + * should be included instead. + * + * \dir Drivers/Board/STK525 + * \brief STK525 board hardware driver files. + * + * This folder contains drivers for hardware on the Atmel STK525 development board. The header files in this folder should + * not be included directly in user applications; the similarly named dispatch header files located in the parent Board directory + * should be included instead. + * + * \dir Drivers/Board/RZUSBSTICK + * \brief RZUSBSTICK board hardware driver files. + * + * This folder contains drivers for hardware on the Atmel RZUSBSTICK board, as used in the Atmel "Raven" wireless kits. The header + * files in this folder should not be included directly in user applications; the similarly named dispatch header files located in + * the parent Board directory should be included instead. + * + * \dir DriverStubs + * \brief Driver stub header files for custom boards, to allow the LUFA board drivers to operate. + * + * This contains stub files for the LUFA board drivers. If the LUFA board drivers are used with board hardare other than those + * directly supported by the library, the BOARD parameter of the application's makefile can be set to "USER", and these stub files + * copied to the "/Board/" directory of the application's folder. When fleshed out with working driver code for the custom board, + * the corresponding LUFA board APIs will work correctly with the non-standard board hardware. + */ diff --git a/LUFA/Doxygen.conf b/LUFA/Doxygen.conf new file mode 100644 index 0000000000..7cb1c71e58 --- /dev/null +++ b/LUFA/Doxygen.conf @@ -0,0 +1,1485 @@ +# Doxyfile 1.5.7.1 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = "LUFA Library" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 000000 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = ./Documentation/ + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = YES + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek, +# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish, +# Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, Slovene, +# Spanish, Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = YES + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate getter +# and setter methods for a property. Setting this option to YES (the default) +# will make doxygen to replace the get and set methods by a property in the +# documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to +# determine which symbols to keep in memory and which to flush to disk. +# When the cache is full, less often used symbols will be written to disk. +# For small to medium size projects (<1000 input files) the default value is +# probably good enough. For larger projects a too small cache size can cause +# doxygen to be busy swapping symbols to and from disk most of the time +# causing a significant performance penality. +# If the system has enough physical memory increasing the cache will improve the +# performance by keeping more symbols in memory. Note that the value works on +# a logarithmic scale so increasing the size by one will rougly double the +# memory usage. The cache size is given by this formula: +# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols + +SYMBOL_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = YES + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = NO + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = NO + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = NO + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by +# doxygen. The layout file controls the global structure of the generated output files +# in an output format independent way. The create the layout file that represents +# doxygen's defaults, run doxygen with the -l option. You can optionally specify a +# file name after the option, if omitted DoxygenLayout.xml will be used as the name +# of the layout file. + +LAYOUT_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = YES + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = YES + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = ./ + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 + +FILE_PATTERNS = *.h \ + *.c \ + *.txt + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = */LowLevel/USBMode.h + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = __* + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = NO + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = YES + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. +# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = YES + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER +# are set, an additional index file will be generated that can be used as input for +# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated +# HTML documentation. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can +# be used to specify the file name of the resulting .qch file. +# The path specified is relative to the HTML output folder. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# Qt Help Project / Namespace. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# Qt Help Project / Virtual Folders. + +QHP_VIRTUAL_FOLDER = doc + +# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can +# be used to specify the location of Qt's qhelpgenerator. +# If non-empty doxygen will try to run qhelpgenerator on the generated +# .qhp file . + +QHG_LOCATION = + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 1 + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to FRAME, a side panel will be generated +# containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. Other possible values +# for this tag are: HIERARCHIES, which will generate the Groups, Directories, +# and Class Hierarchy pages using a tree view instead of an ordered list; +# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which +# disables this behavior completely. For backwards compatibility with previous +# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE +# respectively. + +GENERATE_TREEVIEW = YES + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = YES + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = YES + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = __DOXYGEN__ + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = BUTTLOADTAG + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = NO + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# By default doxygen will write a font called FreeSans.ttf to the output +# directory and reference it in all dot files that doxygen generates. This +# font does not include all possible unicode characters however, so when you need +# these (or just want a differently looking font) you can specify the font name +# using DOT_FONTNAME. You need need to make sure dot is able to find the font, +# which can be done by putting it in a standard location or by setting the +# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory +# containing the font. + +DOT_FONTNAME = FreeSans + +# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. +# The default size is 10pt. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the output directory to look for the +# FreeSans.ttf font (which doxygen will put there itself). If you specify a +# different font using DOT_FONTNAME you can set the path where dot +# can find it using this tag. + +DOT_FONTPATH = + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = NO + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = NO + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = NO + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = NO + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = NO + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = NO + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = "C:/Program Files/Graphviz2.18/bin" + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 15 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 2 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not +# seem to support this out of the box. Warning: Depending on the platform used, +# enabling this option may lead to badly anti-aliased labels on the edges of +# a graph (i.e. they become hard to read). + +DOT_TRANSPARENT = YES + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/LUFA/DriverStubs/Dataflash.h b/LUFA/DriverStubs/Dataflash.h new file mode 100644 index 0000000000..0bef94ebbf --- /dev/null +++ b/LUFA/DriverStubs/Dataflash.h @@ -0,0 +1,81 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +/* + This is a stub driver header file, for implementing custom board + layout hardware with compatible LUFA board specific drivers. If + the library is configured to use the BOARD_USER board mode, this + driver file should be completed and copied into the "/Board/" folder + inside the application's folder. + + This stub is for the board-specific component of the LUFA Dataflash + driver. +*/ + +#ifndef __DATAFLASH_USER_H__ +#define __DATAFLASH_USER_H__ + + /* Includes: */ + // TODO: Add any required includes here + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_DATAFLASH_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Dataflash.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define DATAFLASH_CHIPCS_MASK // TODO: Replace this with a mask of all the /CS pins of all dataflashes + #define DATAFLASH_CHIPCS_DDR // TODO: Replace with the DDR register name for the board's Dataflash ICs + #define DATAFLASH_CHIPCS_PORT // TODO: Replace with the PORT register name for the board's Dataflash ICs + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Constant indicating the total number of dataflash ICs mounted on the selected board. */ + #define DATAFLASH_TOTALCHIPS // TODO: Replace with the number of dataflashes on the board, max 2 + + /** Mask for no dataflash chip selected. */ + #define DATAFLASH_NO_CHIP DATAFLASH_CHIPCS_MASK + + /** Mask for the first dataflash chip selected. */ + #define DATAFLASH_CHIP1 // TODO: Replace with mask to select the first Dataflash chip + + /** Mask for the second dataflash chip selected. */ + #define DATAFLASH_CHIP2 // TODO: Replace with mask to select the second Dataflash chip, if available + + /** Internal main memory page size for the board's dataflash ICs. */ + #define DATAFLASH_PAGE_SIZE // TODO: Replace with the page size for the Dataflash ICs + + /** Total number of pages inside each of the board's dataflash ICs. */ + #define DATAFLASH_PAGES // TODO: Replace with the total number of pages inside one of the Dataflash ICs + +#endif diff --git a/LUFA/DriverStubs/HWB.h b/LUFA/DriverStubs/HWB.h new file mode 100644 index 0000000000..744828d8c3 --- /dev/null +++ b/LUFA/DriverStubs/HWB.h @@ -0,0 +1,84 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +/* + This is a stub driver header file, for implementing custom board + layout hardware with compatible LUFA board specific drivers. If + the library is configured to use the BOARD_USER board mode, this + driver file should be completed and copied into the "/Board/" folder + inside the application's folder. + + This stub is for the board-specific component of the LUFA HWB (Hardware + Button, a physical button on most Atmel USB boards) driver. This could + alternately be driven from any button connected to the USB AVR. +*/ + +#ifndef __HWB_USER_H__ +#define __HWB_USER_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + + // TODO: Add any required includes here + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_HWB_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/HWB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void HWB_Init(void) + { + // TODO: Initialize the appropriate port pin as an input here, with pullup + } + + static inline bool HWB_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline bool HWB_GetStatus(void) + { + // TODO: Return current button status here, debounced if required + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/DriverStubs/Joystick.h b/LUFA/DriverStubs/Joystick.h new file mode 100644 index 0000000000..415976a460 --- /dev/null +++ b/LUFA/DriverStubs/Joystick.h @@ -0,0 +1,99 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +/* + This is a stub driver header file, for implementing custom board + layout hardware with compatible LUFA board specific drivers. If + the library is configured to use the BOARD_USER board mode, this + driver file should be completed and copied into the "/Board/" folder + inside the application's folder. + + This stub is for the board-specific component of the LUFA Joystick + driver, a small surface mount four-way (plus button) digital joystick + on most USB AVR boards. +*/ + +#ifndef __JOYSTICK_USER_H__ +#define __JOYSTICK_USER_H__ + + /* Includes: */ + #include + + #include "../../../Common/Common.h" + + // TODO: Add any required includes here + + /* 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 + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mask for the joystick being pushed in the left direction. */ + #define JOY_LEFT // TODO: Add mask to indicate joystick left position here + + /** Mask for the joystick being pushed in the right direction. */ + #define JOY_RIGHT // TODO: Add mask to indicate joystick right position here + + /** Mask for the joystick being pushed in the upward direction. */ + #define JOY_UP // TODO: Add mask to indicate joystick up position here + + /** Mask for the joystick being pushed in the downward direction. */ + #define JOY_DOWN // TODO: Add mask to indicate joystick down position here + + /** Mask for the joystick being pushed inward. */ + #define JOY_PRESS // TODO: Add mask to indicate joystick pressed position here + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Joystick_Init(void) + { + // TODO: Initialize joystick port pins as inputs with pullups + }; + + static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Joystick_GetStatus(void) + { + // TODO: Return current joystick position data which can be obtained by masking against the JOY_* macros + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/DriverStubs/LEDs.h b/LUFA/DriverStubs/LEDs.h new file mode 100644 index 0000000000..993481d8b0 --- /dev/null +++ b/LUFA/DriverStubs/LEDs.h @@ -0,0 +1,121 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +/* + This is a stub driver header file, for implementing custom board + layout hardware with compatible LUFA board specific drivers. If + the library is configured to use the BOARD_USER board mode, this + driver file should be completed and copied into the "/Board/" folder + inside the application's folder. + + This stub is for the board-specific component of the LUFA LEDs driver, + for the LEDs (up to four) mounted on most USB AVR boards. +*/ + +#ifndef __LEDS_USER_H__ +#define __LEDS_USER_H__ + + /* Includes: */ + #include + + #include "../../../Common/Common.h" + + // TODO: Add any required includes here + +/* 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 // TODO: Add mask for first board LED here + + /** LED mask for the second LED on the board. */ + #define LEDS_LED2 // TODO: Add mask for second board LED here + + /** LED mask for the third LED on the board. */ + #define LEDS_LED3 // TODO: Add mask for third board LED here + + /** LED mask for the fourth LED on the board. */ + #define LEDS_LED4 // TODO: Add mask for fourth board LED here + + /** 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) + { + // TODO: Add code to initialize LED port pins as outputs here + } + + static inline void LEDs_TurnOnLEDs(const uint8_t LedMask) + { + // TODO: Add code to turn on LEDs given in the LedMask mask here, leave others as-is + } + + static inline void LEDs_TurnOffLEDs(const uint8_t LedMask) + { + // TODO: Add code to turn off LEDs given in the LedMask mask here, leave others as-is + } + + static inline void LEDs_SetAllLEDs(const uint8_t LedMask) + { + // TODO: Add code to turn on only LEDs given in the LedMask mask here, all others off + } + + static inline void LEDs_ChangeLEDs(const uint8_t LedMask, const uint8_t ActiveMask) + { + // TODO: Add code to set the Leds in the given LedMask to the status given in ActiveMask here + } + + static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t LEDs_GetLEDs(void) + { + // TODO: Add code to return the current LEDs status' here which can be masked against LED_LED* macros + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/AT90USBXXX/ADC.h b/LUFA/Drivers/AT90USBXXX/ADC.h new file mode 100644 index 0000000000..341b4e1940 --- /dev/null +++ b/LUFA/Drivers/AT90USBXXX/ADC.h @@ -0,0 +1,58 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file is the master dispatch header file for the device-specific ADC driver, for AVRs containing an ADC. + * + * User code should include this file, which will in turn include the correct ADC driver header file for the + * currently selected AVR model. + */ + +#ifndef __ADC_H__ +#define __ADC_H__ + + /* Macros: */ + #if !defined(__DOXYGEN__) + #define INCLUDE_FROM_ADC_H + #define INCLUDE_FROM_CHIP_DRIVER + #endif + + /* Includes: */ + #if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \ + defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \ + defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \ + defined(__AVR_ATmega32U6__)) + #include "AT90USBXXX67/ADC.h" + #else + #error "ADC is not available for the currently selected AVR model." + #endif + +#endif diff --git a/LUFA/Drivers/AT90USBXXX/AT90USBXXX67/ADC.h b/LUFA/Drivers/AT90USBXXX/AT90USBXXX67/ADC.h new file mode 100644 index 0000000000..58027709f6 --- /dev/null +++ b/LUFA/Drivers/AT90USBXXX/AT90USBXXX67/ADC.h @@ -0,0 +1,177 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * ADC driver for the AT90USB1287, AT90USB1286, AT90USB647, AT90USB646, ATMEGA16U4 and ATMEGA32U4 AVRs. + * + * \note This file should not be included directly. It is automatically included as needed by the ADC driver + * dispatch header located in LUFA/Drivers/AT90USBXXX/ADC.h. + */ + +#ifndef __ADC_AT90USBXXX67_H__ +#define __ADC_AT90USBXXX67_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_ADC_H) + #error Do not include this file directly. Include LUFA/Drivers/AT90USBXXX/ADC.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Initializes the ADC, ready for conversions. This must be called before any other ADC operations. + * The "mode" parameter should be a mask comprised of a conversion mode (free running or single) and + * prescaler masks. + */ + #define ADC_Init(mode) MACROS{ ADCSRA = ((1 << ADEN) | mode); }MACROE + + /** Turns off the ADC. If this is called, any further ADC operations will require a call to the + * ADC_Init() macro before the ADC can be used again. + */ + #define ADC_Off() MACROS{ ADCSRA = 0; }MACROE + + /** Indicates if the ADC is enabled. This macro will return boolean true if the ADC subsystem is + * currently enabled, or false otherwise. + */ + #define ADC_GetStatus() ((ADCSRA & (1 << ADEN)) ? true : false) + + /** Indicates if the current ADC conversion is completed, or still in progress. This returns boolean + * false if the reading is still taking place, or true if the conversion is complete and ready to be + * read out with ADC_GetResult(). + */ + #define ADC_IsReadingComplete() (!(ADCSRA & (1 << ADSC))) + + /** Returns the result of the last conversion, as a 16-bit wide integer. */ + #define ADC_GetResult() ADC + + /** Reference mask, for using the voltage present at the AVR's AREF pin for the ADC reference. */ + #define ADC_REFERENCE_AREF 0 + + /** Reference mask, for using the voltage present at the AVR's AVCC pin for the ADC reference. */ + #define ADC_REFERENCE_AVCC (1 << REFS0) + + /** Reference mask, for using the internally generated 2.56V reference voltage as the ADC reference. */ + #define ADC_REFERENCE_INT2560MV ((1 << REFS1)| (1 << REFS0)) + + /** Left-adjusts the 10-bit ADC result, so that the upper 8 bits of the value returned by the + * ADC_GetResult() macro contain the 8 most significant bits of the result. */ + #define ADC_LEFT_ADJUSTED (1 << ADLAR) + + /** Right-adjusts the 10-bit ADC result, so that the lower 8 bits of the value returned by the + * ADC_GetResult() macro contain the 8 least significant bits of the result. */ + #define ADC_RIGHT_ADJUSTED (0 << ADLAR) + + /** Sets the ADC mode to free running, so that conversions take place continuously as fast as the ADC + * is capable of at the given input clock speed. */ + #define ADC_FREE_RUNNING (1 << ADATE) + + /** Sets the ADC mode to single conversion, so that only a single conversion will take place before + * the ADC returns to idle. */ + #define ADC_SINGLE_CONVERSION (0 << ADATE) + + /** Sets the ADC input clock to prescale by a factor of 2 the AVR's system clock. */ + #define ADC_PRESCALE_2 (1 << ADPS0) + + /** Sets the ADC input clock to prescale by a factor of 4 the AVR's system clock. */ + #define ADC_PRESCALE_4 (1 << ADPS1) + + /** Sets the ADC input clock to prescale by a factor of 8 the AVR's system clock. */ + #define ADC_PRESCALE_8 ((1 << ADPS0) | (1 << ADPS1)) + + /** Sets the ADC input clock to prescale by a factor of 16 the AVR's system clock. */ + #define ADC_PRESCALE_16 (1 << ADPS2) + + /** Sets the ADC input clock to prescale by a factor of 32 the AVR's system clock. */ + #define ADC_PRESCALE_32 ((1 << ADPS2) | (1 << ADPS0)) + + /** Sets the ADC input clock to prescale by a factor of 64 the AVR's system clock. */ + #define ADC_PRESCALE_64 ((1 << ADPS2) | (1 << ADPS1)) + + /** Sets the ADC input clock to prescale by a factor of 128 the AVR's system clock. */ + #define ADC_PRESCALE_128 ((1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0)) + + /* Inline Functions: */ + /** Configures the given ADC channel, ready for ADC conversions. This function sets the + * associated port pin as an input and disables the digital portion of the I/O to reduce + * power consumption. + * + * \param Channel ADC channel number to set up for conversions + */ + static inline void ADC_SetupChannel(const uint8_t Channel) + { + DDRD &= ~(1 << Channel); + DIDR0 |= (1 << Channel); + } + + /** Starts the reading of the given channel, but does not wait until the conversion has completed. + * Once executed, the conversion status can be determined via the ADC_IsReadingComplete() macro and + * the result read via the ADC_GetResult() macro. + * + * \param MUXMask Mask comprising of an ADC channel number, reference mask and adjustment mask + */ + static inline void ADC_StartReading(const uint8_t MUXMask) + { + ADMUX = MUXMask; + + ADCSRA |= (1 << ADSC); + } + + /** Performs a complete single reading from channel, including a polling spinloop to wait for the + * conversion to complete, and the returning of the converted value. + * + * \param MUXMask Mask comprising of an ADC channel number, reference mask and adjustment mask + */ + static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask) ATTR_WARN_UNUSED_RESULT; + static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask) + { + ADC_StartReading(MUXMask); + + while (!(ADC_IsReadingComplete())); + + return ADC_GetResult(); + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/AT90USBXXX/SPI.h b/LUFA/Drivers/AT90USBXXX/SPI.h new file mode 100644 index 0000000000..0b333a804e --- /dev/null +++ b/LUFA/Drivers/AT90USBXXX/SPI.h @@ -0,0 +1,139 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Hardware SPI subsystem driver for the supported USB AVRs models. + */ + +#ifndef __SPI_H__ +#define __SPI_H__ + + /* Includes: */ + #include + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define SPI_USE_DOUBLESPEED (1 << 7) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 2. */ + #define SPI_SPEED_FCPU_DIV_2 SPI_USE_DOUBLESPEED + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 4. */ + #define SPI_SPEED_FCPU_DIV_4 0 + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 8. */ + #define SPI_SPEED_FCPU_DIV_8 (SPI_USE_DOUBLESPEED | (1 << SPR0)) + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 16. */ + #define SPI_SPEED_FCPU_DIV_16 (1 << SPR0) + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 32. */ + #define SPI_SPEED_FCPU_DIV_32 (SPI_USE_DOUBLESPEED | (1 << SPR1)) + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 64. */ + #define SPI_SPEED_FCPU_DIV_64 (SPI_USE_DOUBLESPEED | (1 << SPR1) | (1 < SPR0)) + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 128. */ + #define SPI_SPEED_FCPU_DIV_128 ((1 << SPR1) | (1 < SPR0)) + + /* Inline Functions: */ + /** Initializes the SPI subsystem, ready for transfers. Must be called before calling any other + * SPI routines. + * + * \param PrescalerMask Prescaler mask to set the SPI clock speed + * \param Master If true, sets the SPI system to use master mode, slave if false + */ + static inline void SPI_Init(const uint8_t PrescalerMask, const bool Master) + { + DDRB |= ((1 << 1) | (1 << 2)); + PORTB |= ((1 << 0) | (1 << 3)); + + SPCR = ((1 << SPE) | (Master << MSTR) | (1 << CPOL) | (1 << CPHA) | + (PrescalerMask & ~SPI_USE_DOUBLESPEED)); + + if (PrescalerMask & SPI_USE_DOUBLESPEED) + SPSR = (1 << SPI2X); + } + + /** Sends and receives a byte through the SPI interface, blocking until the transfer is complete. + * + * \param Byte Byte to send through the SPI interface + * + * \return Response byte from the attached SPI device + */ + static inline uint8_t SPI_TransferByte(const uint8_t Byte) ATTR_ALWAYSINLINE; + static inline uint8_t SPI_TransferByte(const uint8_t Byte) + { + SPDR = Byte; + while (!(SPSR & (1 << SPIF))); + return SPDR; + } + + /** Sends a byte through the SPI interface, blocking until the transfer is complete. The response + * byte sent to from the attached SPI device is ignored. + * + * \param Byte Byte to send through the SPI interface + */ + static inline void SPI_SendByte(const uint8_t Byte) ATTR_ALWAYSINLINE; + static inline void SPI_SendByte(const uint8_t Byte) + { + SPDR = Byte; + while (!(SPSR & (1 << SPIF))); + } + + /** Sends a dummy byte through the SPI interface, blocking until the transfer is complete. The response + * byte from the attached SPI device is returned. + * + * \return The response byte from the attached SPI device + */ + static inline uint8_t SPI_ReceiveByte(void) ATTR_ALWAYSINLINE ATTR_WARN_UNUSED_RESULT; + static inline uint8_t SPI_ReceiveByte(void) + { + SPDR = 0x00; + while (!(SPSR & (1 << SPIF))); + return SPDR; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/AT90USBXXX/Serial.c b/LUFA/Drivers/AT90USBXXX/Serial.c new file mode 100644 index 0000000000..e1c7449223 --- /dev/null +++ b/LUFA/Drivers/AT90USBXXX/Serial.c @@ -0,0 +1,65 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "Serial.h" + +void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed) +{ + UCSR1A = ((DoubleSpeed) ? (1 << U2X1) : 0); + UCSR1B = ((1 << RXEN1) | (1 << TXEN1)); + UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10)); + + DDRD |= (1 << 3); + PORTD |= (1 << 2); + + UBRR1 = SERIAL_UBBRVAL(BaudRate); +} + +void Serial_TxString_P(const char *FlashStringPtr) +{ + uint8_t CurrByte; + + while ((CurrByte = pgm_read_byte(FlashStringPtr)) != 0x00) + { + Serial_TxByte(CurrByte); + FlashStringPtr++; + } +} + +void Serial_TxString(const char *StringPtr) +{ + uint8_t CurrByte; + + while ((CurrByte = *StringPtr) != 0x00) + { + Serial_TxByte(CurrByte); + StringPtr++; + } +} diff --git a/LUFA/Drivers/AT90USBXXX/Serial.h b/LUFA/Drivers/AT90USBXXX/Serial.h new file mode 100644 index 0000000000..bbf3044faa --- /dev/null +++ b/LUFA/Drivers/AT90USBXXX/Serial.h @@ -0,0 +1,115 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Driver for the USART subsystem on supported USB AVRs. + */ + +#ifndef __SERIAL_H__ +#define __SERIAL_H__ + + /* Includes: */ + #include + #include + #include + + #include "../../Common/Common.h" + #include "../Misc/TerminalCodes.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Indicates whether a character has been received through the USART - boolean false if no character + * has been received, or non-zero if a character is waiting to be read from the reception buffer. + */ + #define Serial_IsCharReceived() ((UCSR1A & (1 << RXC1)) ? true : false) + + /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is + * not set. + */ + #define SERIAL_UBBRVAL(baud) (((F_CPU / 16) / baud) - 1) + + /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is + * set. + */ + #define SERIAL_2X_UBBRVAL(baud) (((F_CPU / 8) / baud) - 1) + + /* Function Prototypes: */ + /** Initializes the USART, ready for serial data transmission and reception. + * + * \param BaudRate Baud rate to configure the USART to + * \param DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate + */ + void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed); + + /** Transmits a given string located in program space (FLASH) through the USART. + * + * \param FlashStringPtr Pointer to a string located in program space + */ + void Serial_TxString_P(const char *FlashStringPtr) ATTR_NON_NULL_PTR_ARG(1); + + /** Transmits a given string located in SRAM memory through the USART. + * + * \param StringPtr Pointer to a string located in SRAM space + */ + void Serial_TxString(const char *StringPtr) ATTR_NON_NULL_PTR_ARG(1); + + /* Inline Functions: */ + /** Transmits a given byte through the USART. + * + * \param DataByte Byte to transmit through the USART + */ + static inline void Serial_TxByte(const char DataByte) + { + while (!(UCSR1A & (1 << UDRE1))); + UDR1 = DataByte; + } + + /** Receives a byte from the USART. + * + * \return Byte received from the USART + */ + static inline char Serial_RxByte(void) + { + while (!(UCSR1A & (1 << RXC1))); + return UDR1; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/AT90USBXXX/Serial_Stream.c b/LUFA/Drivers/AT90USBXXX/Serial_Stream.c new file mode 100644 index 0000000000..d986af4243 --- /dev/null +++ b/LUFA/Drivers/AT90USBXXX/Serial_Stream.c @@ -0,0 +1,45 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "Serial_Stream.h" + +FILE USARTStream = FDEV_SETUP_STREAM(SerialStream_TxByte, SerialStream_RxByte, _FDEV_SETUP_RW); + +int SerialStream_TxByte(char DataByte, FILE *Stream) +{ + Serial_TxByte(DataByte); + + return 0; +} + +int SerialStream_RxByte(FILE *Stream) +{ + return Serial_RxByte(); +} diff --git a/LUFA/Drivers/AT90USBXXX/Serial_Stream.h b/LUFA/Drivers/AT90USBXXX/Serial_Stream.h new file mode 100644 index 0000000000..adde5b95e5 --- /dev/null +++ b/LUFA/Drivers/AT90USBXXX/Serial_Stream.h @@ -0,0 +1,82 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Serial stream driver for the USART subsystem on supported USB AVRs. This makes use of the functions in the + * regular USART driver, but allows the avr-libc standard stream functions (printf, puts, etc.) to work with the + * USART. + **/ + +#ifndef __SERIAL_STREAM_H__ +#define __SERIAL_STREAM_H__ + + /* Includes: */ + #include + #include + + #include "Serial.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* External Variables: */ + extern FILE USARTStream; + + /* Function Prototypes: */ + int SerialStream_TxByte(char DataByte, FILE *Stream) ATTR_NON_NULL_PTR_ARG(2); + int SerialStream_RxByte(FILE *Stream) ATTR_NON_NULL_PTR_ARG(1); + #endif + + /* Public Interface - May be used in end-application: */ + /* Inline Functions: */ + /** Initializes the serial stream (and regular USART driver) so that both the stream and regular + * USART driver functions can be used. Must be called before any stream or regular USART functions. + * + * \param BaudRate Baud rate to configure the USART to + * \param DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate + */ + static inline void SerialStream_Init(const uint32_t BaudRate, const bool DoubleSpeed) + { + Serial_Init(BaudRate, DoubleSpeed); + + stdout = &USARTStream; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/ATAVRUSBRF01/HWB.h b/LUFA/Drivers/Board/ATAVRUSBRF01/HWB.h new file mode 100644 index 0000000000..edf4f8c50d --- /dev/null +++ b/LUFA/Drivers/Board/ATAVRUSBRF01/HWB.h @@ -0,0 +1,79 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific HWB driver header for the ATAVRUSBRF01. + * + * \note This file should not be included directly. It is automatically included as needed by the HWB driver + * dispatch header located in LUFA/Drivers/Board/HWB.h. + */ + +#ifndef __HWB_ATAVRUSBRF01_H__ +#define __HWB_ATAVRUSBRF01_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_HWB_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/HWB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void HWB_Init(void) + { + DDRD &= ~(1 << 7); + PORTD |= (1 << 7); + } + + static inline bool HWB_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline bool HWB_GetStatus(void) + { + return (!(PIND & (1 << 7))); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/ATAVRUSBRF01/LEDs.h b/LUFA/Drivers/Board/ATAVRUSBRF01/LEDs.h new file mode 100644 index 0000000000..626d8cecf3 --- /dev/null +++ b/LUFA/Drivers/Board/ATAVRUSBRF01/LEDs.h @@ -0,0 +1,120 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific LED driver header for the ATAVRUSBRF01. + * + * \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. + */ + +#ifndef __LEDS_ATAVRUSBRF01_H__ +#define __LEDS_ATAVRUSBRF01_H__ + + /* Includes: */ + #include + + #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_PORTD_LEDS (LEDS_LED1 | LEDS_LED2) + #define LEDS_PORTE_LEDS (LEDS_LED3 | LEDS_LED4) + + #define LEDS_PORTE_MASK_SHIFT 4 + #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 the second LED on the board. */ + #define LEDS_LED2 (1 << 1) + + /** 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) + { + DDRD |= LEDS_ALL_LEDS; + PORTD &= ~LEDS_ALL_LEDS; + } + + static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) + { + PORTD |= (LEDMask & LEDS_ALL_LEDS); + } + + static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) + { + PORTD &= ~(LEDMask & LEDS_ALL_LEDS); + } + + static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) + { + PORTD = (PORTD & ~LEDS_ALL_LEDS) | (LEDMask & LEDS_ALL_LEDS); + } + + static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask) + { + PORTD = (PORTD & ~(LEDMask & LEDS_ALL_LEDS)) | (ActiveMask & LEDS_ALL_LEDS)) + } + + 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 diff --git a/LUFA/Drivers/Board/Dataflash.h b/LUFA/Drivers/Board/Dataflash.h new file mode 100644 index 0000000000..08deb50d4e --- /dev/null +++ b/LUFA/Drivers/Board/Dataflash.h @@ -0,0 +1,210 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file is the master dispatch header file for the board-specific dataflash driver, for boards containing + * dataflash ICs for external non-volatile storage. + * + * User code should include this file, which will in turn include the correct dataflash driver header file for + * the currently selected board. + * + * If the BOARD value is set to BOARD_USER, this will include the /Board/Dataflash.h file in the user project + * directory. + */ + +#ifndef __DATAFLASH_H__ +#define __DATAFLASH_H__ + + /* Macros: */ + #if !defined(__DOXYGEN__) + #define INCLUDE_FROM_DATAFLASH_H + #define INCLUDE_FROM_BOARD_DRIVER + #endif + + /* Includes: */ + #include "../AT90USBXXX/SPI.h" + #include "../../Common/Common.h" + + #if !defined(BOARD) + #error BOARD must be set in makefile to a value specified in BoardTypes.h. + #elif (BOARD == BOARD_USBKEY) + #include "USBKEY/Dataflash.h" + #elif (BOARD == BOARD_STK525) + #include "STK525/Dataflash.h" + #elif (BOARD == BOARD_STK526) + #include "STK526/Dataflash.h" + #elif (BOARD == BOARD_USER) + #include "Board/Dataflash.h" + #else + #error The selected board does not contain a dataflash IC. + #endif + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Returns the mask of the currently selected Dataflash chip, either DATAFLASH_NO_CHIP or a + * DATAFLASH_CHIPn mask (where n is the chip number). + */ + #define Dataflash_GetSelectedChip() (DATAFLASH_CHIPCS_PORT & DATAFLASH_CHIPCS_MASK) + + /** Selects the dataflash chip given as a chip mask, in the form of DATAFLASH_CHIPn (where n + * is the chip number). + */ + #define Dataflash_SelectChip(mask) MACROS{ DATAFLASH_CHIPCS_PORT = ((DATAFLASH_CHIPCS_PORT \ + & ~DATAFLASH_CHIPCS_MASK) | mask); }MACROE + + /** Deselects the current dataflash chip, so that no dataflash is selected. */ + #define Dataflash_DeselectChip() Dataflash_SelectChip(DATAFLASH_NO_CHIP) + + /* Inline Functions: */ + /** Initializes the dataflash driver (including the SPI driver) so that commands and data may be + * sent to an attached dataflash IC. + * + * \param PrescalerMask SPI prescaler mask, see SPI.h documentation + */ + static inline void Dataflash_Init(const uint8_t PrescalerMask) + { + DATAFLASH_CHIPCS_DDR |= DATAFLASH_CHIPCS_MASK; + DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK; + + SPI_Init(PrescalerMask, true); + } + + /** Sends a byte to the currently selected dataflash IC, and returns a byte from the dataflash. + * + * \param Byte of data to send to the dataflash + * + * \return Last response byte from the dataflash + */ + static inline uint8_t Dataflash_TransferByte(const uint8_t Byte) ATTR_ALWAYSINLINE; + static inline uint8_t Dataflash_TransferByte(const uint8_t Byte) + { + return SPI_TransferByte(Byte); + } + + /** Sends a byte to the currently selected dataflash IC, and ignores the next byte from the dataflash. + * + * \param Byte of data to send to the dataflash + */ + static inline void Dataflash_SendByte(const uint8_t Byte) ATTR_ALWAYSINLINE; + static inline void Dataflash_SendByte(const uint8_t Byte) + { + SPI_SendByte(Byte); + } + + /** Sends a dummy byte to the currently selected dataflash IC, and returns the next byte from the dataflash. + * + * \return Last response byte from the dataflash + */ + static inline uint8_t Dataflash_ReceiveByte(void) ATTR_ALWAYSINLINE ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Dataflash_ReceiveByte(void) + { + return SPI_ReceiveByte(); + } + + /** Toggles the select line of the currently selected dataflash IC, so that it is ready to receive + * a new command. + */ + static inline void Dataflash_ToggleSelectedChipCS(void) + { + #if (DATAFLASH_TOTALCHIPS == 2) + uint8_t SelectedChipMask = Dataflash_GetSelectedChip(); + + Dataflash_DeselectChip(); + Dataflash_SelectChip(SelectedChipMask); + #else + Dataflash_DeselectChip(); + Dataflash_SelectChip(DATAFLASH_CHIP1); + #endif + } + + /** Spinloops while the currently selected dataflash is busy executing a command, such as a main + * memory page program or main memory to buffer transfer. + */ + static inline void Dataflash_WaitWhileBusy(void) + { + Dataflash_ToggleSelectedChipCS(); + Dataflash_SendByte(DF_CMD_GETSTATUS); + while (!(Dataflash_ReceiveByte() & DF_STATUS_READY)); + } + + /** Selects a dataflash IC from the given page number, which should range from 0 to + * ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one + * dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside the total number + * of pages contained in the boards dataflash ICs, all dataflash ICs are deselected. + * + * \param PageAddress Address of the page to manipulate, ranging from + * ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). + */ + static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress) + { + Dataflash_DeselectChip(); + + if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS)) + return; + + #if (DATAFLASH_TOTALCHIPS == 2) + if (PageAddress & 0x01) + Dataflash_SelectChip(DATAFLASH_CHIP2); + else + Dataflash_SelectChip(DATAFLASH_CHIP1); + #else + Dataflash_SelectChip(DATAFLASH_CHIP1); + #endif + } + + /** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with + * dataflash commands which require a complete 24-byte address. + * + * \param PageAddress Page address within the selected dataflash IC + * \param BufferByte Address within the dataflash's buffer + */ + static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte) + { + #if (DATAFLASH_TOTALCHIPS == 2) + PageAddress >>= 1; + #endif + + Dataflash_SendByte(PageAddress >> 5); + Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8)); + Dataflash_SendByte(BufferByte); + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/HWB.h b/LUFA/Drivers/Board/HWB.h new file mode 100644 index 0000000000..43aac9b5ca --- /dev/null +++ b/LUFA/Drivers/Board/HWB.h @@ -0,0 +1,87 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file is the master dispatch header file for the board-specific HWB driver, for boards containing a + * physical pushbutton connected to the AVR's HWB IO pin. + * + * User code should include this file, which will in turn include the correct HWB driver header file for the + * currently selected board. + * + * If the BOARD value is set to BOARD_USER, this will include the /Board/HWB.h file in the user project + * directory. + */ + +#ifndef __HWB_H__ +#define __HWB_H__ + + /* Macros: */ + #if !defined(__DOXYGEN__) + #define INCLUDE_FROM_HWB_H + #define INCLUDE_FROM_BOARD_DRIVER + #endif + + /* Includes: */ + #include "../../Common/Common.h" + + #if !defined(BOARD) + #error BOARD must be set in makefile to a value specified in BoardTypes.h. + #elif (BOARD == BOARD_USBKEY) + #include "USBKEY/HWB.h" + #elif (BOARD == BOARD_STK525) + #include "STK525/HWB.h" + #elif (BOARD == BOARD_STK526) + #include "STK526/HWB.h" + #elif (BOARD == BOARD_ATAVRUSBRF01) + #include "ATAVRUSBRF01/HWB.h" + #elif (BOARD == BOARD_USER) + #include "Board/HWB.h" + #else + #error The selected board does not contain a HWB. + #endif + + /* Psudo-Functions for Doxygen: */ + #if defined(__DOXYGEN__) + /** Initializes the HWB driver, so that the current button position can be read. This sets the appropriate + * I/O pin to an input with pull-up enabled. + * + * This must be called before any HWB functions are used. + */ + static inline void HWB_Init(void); + + /** Returns the current position of the HWB button on the board. + * + * \return Boolean true if the button is currently pressed, false otherwise + */ + static inline bool HWB_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + #endif + +#endif diff --git a/LUFA/Drivers/Board/Joystick.h b/LUFA/Drivers/Board/Joystick.h new file mode 100644 index 0000000000..1f57e62c3f --- /dev/null +++ b/LUFA/Drivers/Board/Joystick.h @@ -0,0 +1,85 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file is the master dispatch header file for the board-specific Joystick driver, for boards containing a + * 5-way joystick. + * + * User code should include this file, which will in turn include the correct joystick driver header file for the + * currently selected board. + * + * If the BOARD value is set to BOARD_USER, this will include the /Board/Joystick.h file in the user project + * directory. + */ + +#ifndef __JOYSTICK_H__ +#define __JOYSTICK_H__ + + /* Macros: */ + #if !defined(__DOXYGEN__) + #define INCLUDE_FROM_JOYSTICK_H + #define INCLUDE_FROM_BOARD_DRIVER + #endif + + /* Includes: */ + #include "../../Common/Common.h" + + #if !defined(BOARD) + #error BOARD must be set in makefile to a value specified in BoardTypes.h. + #elif (BOARD == BOARD_USBKEY) + #include "USBKEY/Joystick.h" + #elif (BOARD == BOARD_STK525) + #include "STK525/Joystick.h" + #elif (BOARD == BOARD_STK526) + #include "STK526/Joystick.h" + #elif (BOARD == BOARD_USER) + #include "Board/Joystick.h" + #else + #error The selected board does not contain a joystick. + #endif + + /* Psudo-Functions for Doxygen: */ + #if defined(__DOXYGEN__) + /** Initializes the joystick driver so that the joystick position can be read. This sets the appropriate + * I/O pins to inputs with their pull-ups enabled. + */ + static inline void Joystick_Init(void); + + /** Returns the current status of the joystick, as a mask indicating the direction the joystick is + * currently facing in (multiple bits can be set). + * + * \return Mask indicating the joystick direction - see corresponding board specific Joystick.h file + * for direction masks + */ + static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + #endif + +#endif diff --git a/LUFA/Drivers/Board/LEDs.h b/LUFA/Drivers/Board/LEDs.h new file mode 100644 index 0000000000..cda15a4214 --- /dev/null +++ b/LUFA/Drivers/Board/LEDs.h @@ -0,0 +1,113 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * This file is the master dispatch header file for the board-specific LED driver, for boards containing user + * controllable LEDs. + * + * User code should include this file, which will in turn include the correct LED driver header file for the + * currently selected board. + * + * If the BOARD value is set to BOARD_USER, this will include the /Board/LEDs.h file in the user project + * directory. + */ + +#ifndef __LEDS_H__ +#define __LEDS_H__ + + /* Macros: */ + #if !defined(__DOXYGEN__) + #define INCLUDE_FROM_LEDS_H + #define INCLUDE_FROM_BOARD_DRIVER + #endif + + /* Includes: */ + #include "../../Common/Common.h" + + #if !defined(BOARD) + #error BOARD must be set in makefile to a value specified in BoardTypes.h. + #elif (BOARD == BOARD_USBKEY) + #include "USBKEY/LEDs.h" + #elif (BOARD == BOARD_STK525) + #include "STK525/LEDs.h" + #elif (BOARD == BOARD_STK526) + #include "STK526/LEDs.h" + #elif (BOARD == BOARD_RZUSBSTICK) + #include "RZUSBSTICK/LEDs.h" + #elif (BOARD == BOARD_ATAVRUSBRF01) + #include "ATAVRUSBRF01/LEDs.h" + #elif (BOARD == BOARD_USER) + #include "Board/LEDs.h" + #endif + + /* Psudo-Functions for Doxygen: */ + #if defined(__DOXYGEN__) + /** Initializes the board LED driver so that the LEDs can be controlled. This sets the appropriate port + * I/O pins as outputs, and sets the LEDs to default to off. + */ + static inline void LEDs_Init(void); + + /** Turns on the LEDs specified in the given LED mask. + * + * \param LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) + */ + static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask); + + /** Turns off the LEDs specified in the given LED mask. + * + * \param LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) + */ + static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask); + + /** Turns off all LEDs not specified in the given LED mask, and turns on all the LEDs in the given LED + * mask. + * + * \param LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) + */ + static inline void LEDs_SetAllLEDs(const uint8_t LEDMask); + + /** Turns off all LEDs in the LED mask that are not set in the active mask, and turns on all the LEDs + * specified in both the LED and active masks. + * + * \param LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) + * \param ActiveMask Mask of whether the LEDs in the LED mask should be turned on or off + */ + static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask); + + /** Returns the status of all the board LEDs; set LED masks in the return value indicate that the + * corresponding LED is on. + * + * \return Mask of the board LEDs which are currently turned on + */ + static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; + #endif + +#endif diff --git a/LUFA/Drivers/Board/RZUSBSTICK/LEDs.h b/LUFA/Drivers/Board/RZUSBSTICK/LEDs.h new file mode 100644 index 0000000000..38cbed0cff --- /dev/null +++ b/LUFA/Drivers/Board/RZUSBSTICK/LEDs.h @@ -0,0 +1,141 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific LED driver header for the RZUSBSTICK. + * + * \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. + */ + +#ifndef __LEDS_RZUSBSTICK_H__ +#define __LEDS_RZUSBSTICK_H__ + + /* Includes: */ + #include + + #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_PORTD_LEDS (LEDS_LED1 | LEDS_LED2) + #define LEDS_PORTE_LEDS (LEDS_LED3 | LEDS_LED4) + + #define LEDS_PORTE_MASK_SHIFT 4 + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** LED mask for the first LED on the board. */ + #define LEDS_LED1 (1 << 7) + + /** LED mask for the second LED on the board. */ + #define LEDS_LED2 (1 << 5) + + /** LED mask for the third LED on the board. */ + #define LEDS_LED3 ((1 << 6) >> LEDS_PORTE_MASK_SHIFT) + + /** LED mask for the fourth LED on the board. */ + #define LEDS_LED4 ((1 << 7) >> LEDS_PORTE_MASK_SHIFT) + + /** 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) + { + DDRD |= LEDS_PORTD_LEDS; + PORTD &= ~LEDS_LED1; + PORTD |= LEDS_LED2; + + DDRE |= (LEDS_PORTE_LEDS << LEDS_PORTE_MASK_SHIFT); + PORTE |= (LEDS_PORTE_LEDS << LEDS_PORTE_MASK_SHIFT); + } + + static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) + { + PORTD |= (LEDMask & LEDS_LED1); + PORTD &= ~(LEDMask & LEDS_LED2); + PORTE &= ~((LEDMask & LEDS_PORTE_LEDS) << LEDS_PORTE_MASK_SHIFT); + } + + static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) + { + PORTD &= ~(LEDMask & LEDS_LED1); + PORTD |= (LEDMask & LEDS_LED2); + PORTE |= ((LEDMask & LEDS_PORTE_LEDS) << LEDS_PORTE_MASK_SHIFT); + } + + static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) + { + PORTD = (((PORTD & ~LEDS_LED1) | (LEDMask & LEDS_LED1)) | + ((PORTD | LEDS_LED2) & ~(LEDMask & LEDS_LED2))); + PORTE = ((PORTE | (LEDS_PORTE_LEDS << LEDS_PORTE_MASK_SHIFT)) & + ~((LEDMask & LEDS_PORTE_LEDS) << LEDS_PORTE_MASK_SHIFT)); + } + + static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask) + { + PORTD = (((PORTD & ~(LEDMask & LEDS_LED1)) | (ActiveMask & LEDS_LED1)) | + ((PORTD | (LEDMask & LEDS_LED2)) & ~(ActiveMask & LEDS_LED2))); + PORTE = ((PORTE | ((LEDMask & LEDS_PORTE_LEDS) << LEDS_PORTE_MASK_SHIFT)) & + ~((ActiveMask & LEDS_PORTE_LEDS) << LEDS_PORTE_MASK_SHIFT)); + } + + static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t LEDs_GetLEDs(void) + { + return (((PORTD & LEDS_LED1) | (~PORTD & LEDS_LED2)) | + ((~PORTE & (LEDS_PORTE_LEDS << LEDS_PORTE_MASK_SHIFT)) >> LEDS_PORTE_MASK_SHIFT)); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/STK525/AT45DB321C.h b/LUFA/Drivers/Board/STK525/AT45DB321C.h new file mode 100644 index 0000000000..ac29967e6b --- /dev/null +++ b/LUFA/Drivers/Board/STK525/AT45DB321C.h @@ -0,0 +1,84 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific Dataflash commands header for the AT45DB321C as mounted on the STK525. + * + * \note This file should not be included directly. It is automatically included as needed by the dataflash driver + * dispatch header located in LUFA/Drivers/Board/Dataflash.h. + */ + +#ifndef __DATAFLASH_CMDS_H__ +#define __DATAFLASH_CMDS_H__ + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #define DF_STATUS_READY (1 << 7) + #define DF_STATUS_COMPMISMATCH (1 << 6) + #define DF_STATUS_SECTORPROTECTION_ON (1 << 1) + + #define DF_MANUFACTURER_ATMEL 0x1F + + #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 diff --git a/LUFA/Drivers/Board/STK525/Dataflash.h b/LUFA/Drivers/Board/STK525/Dataflash.h new file mode 100644 index 0000000000..3f30f97b95 --- /dev/null +++ b/LUFA/Drivers/Board/STK525/Dataflash.h @@ -0,0 +1,75 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific HWB driver header for the STK525. + * + * \note This file should not be included directly. It is automatically included as needed by the dataflash driver + * dispatch header located in LUFA/Drivers/Board/Dataflash.h. + */ + +#ifndef __DATAFLASH_STK525_H__ +#define __DATAFLASH_STK525_H__ + + /* Includes: */ + #include "AT45DB321C.h" + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_DATAFLASH_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Dataflash.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define DATAFLASH_CHIPCS_MASK (1 << 4) + #define DATAFLASH_CHIPCS_DDR DDRB + #define DATAFLASH_CHIPCS_PORT PORTB + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Constant indicating the total number of dataflash ICs mounted on the selected board. */ + #define DATAFLASH_TOTALCHIPS 1 + + /** Mask for no dataflash chip selected. */ + #define DATAFLASH_NO_CHIP DATAFLASH_CHIPCS_MASK + + /** Mask for the first dataflash chip selected. */ + #define DATAFLASH_CHIP1 0 + + /** Internal main memory page size for the board's dataflash IC. */ + #define DATAFLASH_PAGE_SIZE 512 + + /** Total number of pages inside the board's dataflash IC. */ + #define DATAFLASH_PAGES 8192 + +#endif diff --git a/LUFA/Drivers/Board/STK525/HWB.h b/LUFA/Drivers/Board/STK525/HWB.h new file mode 100644 index 0000000000..a0ff72de13 --- /dev/null +++ b/LUFA/Drivers/Board/STK525/HWB.h @@ -0,0 +1,79 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific HWB driver header for the STK525. + * + * \note This file should not be included directly. It is automatically included as needed by the HWB driver + * dispatch header located in LUFA/Drivers/Board/HWB.h. + */ + +#ifndef __HWB_STK525_H__ +#define __HWB_STK525_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_HWB_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/HWB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void HWB_Init(void) + { + DDRE &= ~(1 << 2); + PORTE |= (1 << 2); + } + + static inline bool HWB_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline bool HWB_GetStatus(void) + { + return (!(PINE & (1 << 2))); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/STK525/Joystick.h b/LUFA/Drivers/Board/STK525/Joystick.h new file mode 100644 index 0000000000..58aed4f80d --- /dev/null +++ b/LUFA/Drivers/Board/STK525/Joystick.h @@ -0,0 +1,104 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific joystick driver header for the STK525. + * + * \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. + */ + +#ifndef __JOYSTICK_STK525_H__ +#define __JOYSTICK_STK525_H__ + + /* Includes: */ + #include + + #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_BMASK ((1 << 5) | (1 << 6) | (1 << 7)) + #define JOY_EMASK ((1 << 4) | (1 << 5)) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mask for the joystick being pushed in the left direction. */ + #define JOY_LEFT (1 << 6) + + /** Mask for the joystick being pushed in the right direction. */ + #define JOY_RIGHT ((1 << 4) >> 1) + + /** Mask for the joystick being pushed in the upward direction. */ + #define JOY_UP (1 << 7) + + /** Mask for the joystick being pushed in the downward direction. */ + #define JOY_DOWN ((1 << 5) >> 1) + + /** Mask for the joystick being pushed inward. */ + #define JOY_PRESS (1 << 5) + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Joystick_Init(void) + { + DDRB &= ~(JOY_BMASK); + DDRE &= ~(JOY_EMASK); + + PORTB |= JOY_BMASK; + PORTE |= JOY_EMASK; + }; + + static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Joystick_GetStatus(void) + { + return (((uint8_t)~PINB & JOY_BMASK) | (((uint8_t)~PINE & JOY_EMASK) >> 1)); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/STK525/LEDs.h b/LUFA/Drivers/Board/STK525/LEDs.h new file mode 100644 index 0000000000..13f626c2b0 --- /dev/null +++ b/LUFA/Drivers/Board/STK525/LEDs.h @@ -0,0 +1,117 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific LED driver header for the STK525. + * + * \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. + */ + +#ifndef __LEDS_STK525_H__ +#define __LEDS_STK525_H__ + + /* Includes: */ + #include + + #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 the second LED on the board. */ + #define LEDS_LED2 (1 << 5) + + /** LED mask for the third LED on the board. */ + #define LEDS_LED3 (1 << 7) + + /** LED mask for the fourth LED on the board. */ + #define LEDS_LED4 (1 << 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) + { + 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 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 diff --git a/LUFA/Drivers/Board/STK526/AT45DB642D.h b/LUFA/Drivers/Board/STK526/AT45DB642D.h new file mode 100644 index 0000000000..dd38ed1dfe --- /dev/null +++ b/LUFA/Drivers/Board/STK526/AT45DB642D.h @@ -0,0 +1,94 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific Dataflash commands header for the AT45DB642D as mounted on the STK526. + * + * \note This file should not be included directly. It is automatically included as needed by the dataflash driver + * dispatch header located in LUFA/Drivers/Board/Dataflash.h. + */ + +#ifndef __DATAFLASH_CMDS_H__ +#define __DATAFLASH_CMDS_H__ + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #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 + + #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 diff --git a/LUFA/Drivers/Board/STK526/Dataflash.h b/LUFA/Drivers/Board/STK526/Dataflash.h new file mode 100644 index 0000000000..177fefaaba --- /dev/null +++ b/LUFA/Drivers/Board/STK526/Dataflash.h @@ -0,0 +1,75 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific HWB driver header for the STK525. + * + * \note This file should not be included directly. It is automatically included as needed by the dataflash driver + * dispatch header located in LUFA/Drivers/Board/Dataflash.h. + */ + +#ifndef __DATAFLASH_STK526_H__ +#define __DATAFLASH_STK526_H__ + + /* Includes: */ + #include "AT45DB642D.h" + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_DATAFLASH_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Dataflash.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define DATAFLASH_CHIPCS_MASK (1 << 2) + #define DATAFLASH_CHIPCS_DDR DDRC + #define DATAFLASH_CHIPCS_PORT PORTC + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Constant indicating the total number of dataflash ICs mounted on the selected board. */ + #define DATAFLASH_TOTALCHIPS 1 + + /** Mask for no dataflash chip selected. */ + #define DATAFLASH_NO_CHIP DATAFLASH_CHIPCS_MASK + + /** Mask for the first dataflash chip selected. */ + #define DATAFLASH_CHIP1 0 + + /** Internal main memory page size for the board's dataflash IC. */ + #define DATAFLASH_PAGE_SIZE 1024 + + /** Total number of pages inside the board's dataflash IC. */ + #define DATAFLASH_PAGES 8192 + +#endif diff --git a/LUFA/Drivers/Board/STK526/HWB.h b/LUFA/Drivers/Board/STK526/HWB.h new file mode 100644 index 0000000000..3bd2f9952f --- /dev/null +++ b/LUFA/Drivers/Board/STK526/HWB.h @@ -0,0 +1,79 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific HWB driver header for the STK526. + * + * \note This file should not be included directly. It is automatically included as needed by the HWB driver + * dispatch header located in LUFA/Drivers/Board/HWB.h. + */ + +#ifndef __HWB_STK526_H__ +#define __HWB_STK526_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_HWB_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/HWB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void HWB_Init(void) + { + DDRD &= ~(1 << 7); + PORTD |= (1 << 7); + } + + static inline bool HWB_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline bool HWB_GetStatus(void) + { + return (!(PIND & (1 << 7))); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/STK526/Joystick.h b/LUFA/Drivers/Board/STK526/Joystick.h new file mode 100644 index 0000000000..e5cd2e47c6 --- /dev/null +++ b/LUFA/Drivers/Board/STK526/Joystick.h @@ -0,0 +1,101 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific joystick driver header for the STK526. + * + * \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. + */ + +#ifndef __JOYSTICK_STK526_H__ +#define __JOYSTICK_STK526_H__ + + /* Includes: */ + #include + + #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_BMASK ((1 << 0) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7)) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mask for the joystick being pushed in the left direction. */ + #define JOY_LEFT (1 << 4) + + /** Mask for the joystick being pushed in the right direction. */ + #define JOY_RIGHT (1 << 6) + + /** Mask for the joystick being pushed in the upward direction. */ + #define JOY_UP (1 << 5) + + /** Mask for the joystick being pushed in the downward direction. */ + #define JOY_DOWN (1 << 7) + + /** Mask for the joystick being pushed inward. */ + #define JOY_PRESS (1 << 0) + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Joystick_Init(void) + { + DDRB &= ~JOY_BMASK; + + PORTB |= JOY_BMASK; + }; + + static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Joystick_GetStatus(void) + { + return ((uint8_t)~PINB & JOY_BMASK); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/STK526/LEDs.h b/LUFA/Drivers/Board/STK526/LEDs.h new file mode 100644 index 0000000000..fc88a57339 --- /dev/null +++ b/LUFA/Drivers/Board/STK526/LEDs.h @@ -0,0 +1,117 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific LED driver header for the STK526. + * + * \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. + */ + +#ifndef __LEDS_STK526_H__ +#define __LEDS_STK526_H__ + + /* Includes: */ + #include + + #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 << 1) + + /** LED mask for the second LED on the board. */ + #define LEDS_LED2 (1 << 0) + + /** LED mask for the third LED on the board. */ + #define LEDS_LED3 (1 << 5) + + /** LED mask for the fourth LED on the board. */ + #define LEDS_LED4 (1 << 4) + + /** 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) + { + 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 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 diff --git a/LUFA/Drivers/Board/Temperature.c b/LUFA/Drivers/Board/Temperature.c new file mode 100644 index 0000000000..f908ac9649 --- /dev/null +++ b/LUFA/Drivers/Board/Temperature.c @@ -0,0 +1,60 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "Temperature.h" + +static const uint16_t PROGMEM Temperature_Lookup[] = { + 0x3B4, 0x3B0, 0x3AB, 0x3A6, 0x3A0, 0x39A, 0x394, 0x38E, 0x388, 0x381, 0x37A, 0x373, + 0x36B, 0x363, 0x35B, 0x353, 0x34A, 0x341, 0x338, 0x32F, 0x325, 0x31B, 0x311, 0x307, + 0x2FC, 0x2F1, 0x2E6, 0x2DB, 0x2D0, 0x2C4, 0x2B8, 0x2AC, 0x2A0, 0x294, 0x288, 0x27C, + 0x26F, 0x263, 0x256, 0x24A, 0x23D, 0x231, 0x225, 0x218, 0x20C, 0x200, 0x1F3, 0x1E7, + 0x1DB, 0x1CF, 0x1C4, 0x1B8, 0x1AC, 0x1A1, 0x196, 0x18B, 0x180, 0x176, 0x16B, 0x161, + 0x157, 0x14D, 0x144, 0x13A, 0x131, 0x128, 0x11F, 0x117, 0x10F, 0x106, 0x0FE, 0x0F7, + 0x0EF, 0x0E8, 0x0E1, 0x0DA, 0x0D3, 0x0CD, 0x0C7, 0x0C0, 0x0BA, 0x0B5, 0x0AF, 0x0AA, + 0x0A4, 0x09F, 0x09A, 0x096, 0x091, 0x08C, 0x088, 0x084, 0x080, 0x07C, 0x078, 0x074, + 0x071, 0x06D, 0x06A, 0x067, 0x064, 0x061, 0x05E, 0x05B, 0x058, 0x055, 0x053, 0x050, + 0x04E, 0x04C, 0x049, 0x047, 0x045, 0x043, 0x041, 0x03F, 0x03D, 0x03C, 0x03A, 0x038 + }; + +int8_t Temperature_GetTemperature(void) +{ + uint16_t Temp_ADC = ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | TEMP_ADC_CHANNEL); + + if (Temp_ADC > pgm_read_word(&Temperature_Lookup[0])) + return TEMP_MIN_TEMP; + + for (uint16_t Index = 0; Index < TEMP_TABLE_SIZE; Index++) + { + if (Temp_ADC > pgm_read_word(&Temperature_Lookup[Index])) + return (Index + TEMP_TABLE_OFFSET); + } + + return TEMP_MAX_TEMP; +} diff --git a/LUFA/Drivers/Board/Temperature.h b/LUFA/Drivers/Board/Temperature.h new file mode 100644 index 0000000000..c205093a86 --- /dev/null +++ b/LUFA/Drivers/Board/Temperature.h @@ -0,0 +1,100 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Temperature sensor board driver for the USB boards which contain a temperature sensor. + */ + +#ifndef __TEMPERATURE_H__ +#define __TEMPERATURE_H__ + + /* Macros: */ + #if !defined(__DOXYGEN__) + #define INCLUDE_FROM_BOARD_DRIVER + #endif + + /* Includes: */ + #include + + #include "../AT90USBXXX/ADC.h" + #include "../../Common/Common.h" + + #if !defined(BOARD) + #error #error BOARD must be set in makefile to a value specified in BoardTypes.h. + #elif (BOARD != BOARD_USBKEY) && (BOARD != BOARD_STK525) && (BOARD != BOARD_STK526) + #error The selected board does not contain a temperature sensor. + #endif + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** ADC channel number for the temperature sensor. */ + #define TEMP_ADC_CHANNEL 0 + + /** Minimum returnable temperature from the Temperature_GetTemperature() function. */ + #define TEMP_MIN_TEMP TEMP_TABLE_OFFSET + + /** Maximum returnable temperature from the Temperature_GetTemperature() function. */ + #define TEMP_MAX_TEMP ((TEMP_TABLE_SIZE - 1) + TEMP_TABLE_OFFSET) + + /** Initializes the temperature sensor driver, including setting up the appropriate ADC channel. + * This must be called before any other temperature sensor routines. + * + * The ADC itself (not the ADC channel) must be configured seperately before calling the temperature + * sensor functions. + */ + #define Temperature_Init() ADC_SetupChannel(TEMP_ADC_CHANNEL); + + /* Function Prototypes: */ + /** Performs a complete ADC on the temperature sensor channel, and converts the result into a + * valid temperature between TEMP_MIN_TEMP and TEMP_MAX_TEMP in degrees Celcius. + * + * \return Signed temperature in degrees Celcius + */ + int8_t Temperature_GetTemperature(void) ATTR_WARN_UNUSED_RESULT; + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define TEMP_TABLE_SIZE (sizeof(Temperature_Lookup) / sizeof(Temperature_Lookup[0])) + #define TEMP_TABLE_OFFSET -21 + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/USBKEY/AT45DB642D.h b/LUFA/Drivers/Board/USBKEY/AT45DB642D.h new file mode 100644 index 0000000000..197be1c618 --- /dev/null +++ b/LUFA/Drivers/Board/USBKEY/AT45DB642D.h @@ -0,0 +1,94 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific Dataflash commands header for the AT45DB642D as mounted on the USBKEY. + * + * \note This file should not be included directly. It is automatically included as needed by the dataflash driver + * dispatch header located in LUFA/Drivers/Board/Dataflash.h. + */ + +#ifndef __DATAFLASH_CMDS_H__ +#define __DATAFLASH_CMDS_H__ + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #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 + + #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 diff --git a/LUFA/Drivers/Board/USBKEY/Dataflash.h b/LUFA/Drivers/Board/USBKEY/Dataflash.h new file mode 100644 index 0000000000..848ae32d85 --- /dev/null +++ b/LUFA/Drivers/Board/USBKEY/Dataflash.h @@ -0,0 +1,78 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific HWB driver header for the STK525. + * + * \note This file should not be included directly. It is automatically included as needed by the dataflash driver + * dispatch header located in LUFA/Drivers/Board/Dataflash.h. + */ + +#ifndef __DATAFLASH_USBKEY_H__ +#define __DATAFLASH_USBKEY_H__ + + /* Includes: */ + #include "AT45DB642D.h" + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_DATAFLASH_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Dataflash.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define DATAFLASH_CHIPCS_MASK ((1 << 1) | (1 << 0)) + #define DATAFLASH_CHIPCS_DDR DDRE + #define DATAFLASH_CHIPCS_PORT PORTE + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Constant indicating the total number of dataflash ICs mounted on the selected board. */ + #define DATAFLASH_TOTALCHIPS 2 + + /** Mask for no dataflash chip selected. */ + #define DATAFLASH_NO_CHIP DATAFLASH_CHIPCS_MASK + + /** Mask for the first dataflash chip selected. */ + #define DATAFLASH_CHIP1 (1 << 1) + + /** Mask for the second dataflash chip selected. */ + #define DATAFLASH_CHIP2 (1 << 0) + + /** Internal main memory page size for the board's dataflash ICs. */ + #define DATAFLASH_PAGE_SIZE 1024 + + /** Total number of pages inside each of the board's dataflash ICs. */ + #define DATAFLASH_PAGES 8192 + +#endif diff --git a/LUFA/Drivers/Board/USBKEY/HWB.h b/LUFA/Drivers/Board/USBKEY/HWB.h new file mode 100644 index 0000000000..750368b19a --- /dev/null +++ b/LUFA/Drivers/Board/USBKEY/HWB.h @@ -0,0 +1,79 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific HWB driver header for the USBKEY. + * + * \note This file should not be included directly. It is automatically included as needed by the HWB driver + * dispatch header located in LUFA/Drivers/Board/HWB.h. + */ + +#ifndef __HWB_USBKEY_H__ +#define __HWB_USBKEY_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(INCLUDE_FROM_HWB_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/HWB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void HWB_Init(void) + { + DDRE &= ~(1 << 2); + PORTE |= (1 << 2); + } + + static inline bool HWB_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline bool HWB_GetStatus(void) + { + return (!(PINE & (1 << 2))); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/USBKEY/Joystick.h b/LUFA/Drivers/Board/USBKEY/Joystick.h new file mode 100644 index 0000000000..6c2d72aee5 --- /dev/null +++ b/LUFA/Drivers/Board/USBKEY/Joystick.h @@ -0,0 +1,104 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific joystick driver header for the USBKEY. + * + * \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. + */ + +#ifndef __JOYSTICK_USBKEY_H__ +#define __JOYSTICK_USBKEY_H__ + + /* Includes: */ + #include + + #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_BMASK ((1 << 5) | (1 << 6) | (1 << 7)) + #define JOY_EMASK ((1 << 4) | (1 << 5)) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mask for the joystick being pushed in the left direction. */ + #define JOY_LEFT (1 << 6) + + /** Mask for the joystick being pushed in the right direction. */ + #define JOY_RIGHT ((1 << 4) >> 1) + + /** Mask for the joystick being pushed in the upward direction. */ + #define JOY_UP (1 << 7) + + /** Mask for the joystick being pushed in the downward direction. */ + #define JOY_DOWN ((1 << 5) >> 1) + + /** Mask for the joystick being pushed inward. */ + #define JOY_PRESS (1 << 5) + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Joystick_Init(void) + { + DDRB &= ~(JOY_BMASK); + DDRE &= ~(JOY_EMASK); + + PORTB |= JOY_BMASK; + PORTE |= JOY_EMASK; + }; + + static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Joystick_GetStatus(void) + { + return (((uint8_t)~PINB & JOY_BMASK) | (((uint8_t)~PINE & JOY_EMASK) >> 1)); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/Board/USBKEY/LEDs.h b/LUFA/Drivers/Board/USBKEY/LEDs.h new file mode 100644 index 0000000000..07a2b7501a --- /dev/null +++ b/LUFA/Drivers/Board/USBKEY/LEDs.h @@ -0,0 +1,117 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Board specific LED driver header for the USBKEY. + * + * \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. + */ + +#ifndef __LEDS_USBKEY_H__ +#define __LEDS_USBKEY_H__ + + /* Includes: */ + #include + + #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 the second LED on the board. */ + #define LEDS_LED2 (1 << 5) + + /** LED mask for the third LED on the board. */ + #define LEDS_LED3 (1 << 7) + + /** LED mask for the fourth LED on the board. */ + #define LEDS_LED4 (1 << 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) + { + 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 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 diff --git a/LUFA/Drivers/Misc/TerminalCodes.h b/LUFA/Drivers/Misc/TerminalCodes.h new file mode 100644 index 0000000000..d6e58708a8 --- /dev/null +++ b/LUFA/Drivers/Misc/TerminalCodes.h @@ -0,0 +1,176 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * ANSI terminal compatible escape sequences. These escape sequences are designed to be concatenated with existing + * strings to modify their display on a compatible terminal application. + * + * \note If desired, the macro DISABLE_TERMINAL_CODES can be defined in the project makefile and passed to the GCC + * compiler via the -D switch to disable the terminal codes without modifying the source, for use with non + * compatible terminals (any terminal code then equate to empty strings). + * + * Example Usage: + * \code + * printf("Some String, " ESC_BOLD_ON " Some bold string"); + * \endcode + */ + +#ifndef __TERMINALCODES_H__ +#define __TERMINALCODES_H__ + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #if !defined(DISABLE_TERMINAL_CODES) + /** Creates an ANSII escape sequence with the payload specified by "c". */ + #define ANSI_ESCAPE_SEQUENCE(c) "\33[" c + #else + #define ANSI_ESCAPE_SEQUENCE(c) + #endif + + /** Resets any escape sequence modifiers back to their defaults. */ + #define ESC_RESET ANSI_ESCAPE_SEQUENCE("0m") + + /** Turns on bold so that any following text is printed to the terminal in bold. */ + #define ESC_BOLD_ON ANSI_ESCAPE_SEQUENCE("1m") + + /** Turns on italics so that any following text is printed to the terminal in italics. */ + #define ESC_ITALICS_ON ANSI_ESCAPE_SEQUENCE("3m") + + /** Turns on underline so that any following text is printed to the terminal underlined. */ + #define ESC_UNDERLINE_ON ANSI_ESCAPE_SEQUENCE("4m") + + /** Turns on inverse so that any following text is printed to the terminal in inverted colours. */ + #define ESC_INVERSE_ON ANSI_ESCAPE_SEQUENCE("7m") + + /** Turns on strikethrough so that any following text is printed to the terminal with a line through the + * center. + */ + #define ESC_STRIKETHROUGH_ON ANSI_ESCAPE_SEQUENCE("9m") + + /** Turns off bold so that any following text is printed to the terminal in non bold. */ + #define ESC_BOLD_OFF ANSI_ESCAPE_SEQUENCE("22m") + + /** Turns off italics so that any following text is printed to the terminal in non italics. */ + #define ESC_ITALICS_OFF ANSI_ESCAPE_SEQUENCE("23m") + + /** Turns off underline so that any following text is printed to the terminal non underlined. */ + #define ESC_UNDERLINE_OFF ANSI_ESCAPE_SEQUENCE("24m") + + /** Turns off inverse so that any following text is printed to the terminal in non inverted colours. */ + #define ESC_INVERSE_OFF ANSI_ESCAPE_SEQUENCE("27m") + + /** Turns off strikethrough so that any following text is printed to the terminal without a line through + * the center. + */ + #define ESC_STRIKETHROUGH_OFF ANSI_ESCAPE_SEQUENCE("29m") + + /** Sets the foreground (text) colour to black. */ + #define ESC_FG_BLACK ANSI_ESCAPE_SEQUENCE("30m") + + /** Sets the foreground (text) colour to red. */ + #define ESC_FG_RED ANSI_ESCAPE_SEQUENCE("31m") + + /** Sets the foreground (text) colour to green. */ + #define ESC_FG_GREEN ANSI_ESCAPE_SEQUENCE("32m") + + /** Sets the foreground (text) colour to yellow. */ + #define ESC_FG_YELLOW ANSI_ESCAPE_SEQUENCE("33m") + + /** Sets the foreground (text) colour to blue. */ + #define ESC_FG_BLUE ANSI_ESCAPE_SEQUENCE("34m") + + /** Sets the foreground (text) colour to magenta. */ + #define ESC_FG_MAGENTA ANSI_ESCAPE_SEQUENCE("35m") + + /** Sets the foreground (text) colour to cyan. */ + #define ESC_FG_CYAN ANSI_ESCAPE_SEQUENCE("36m") + + /** Sets the foreground (text) colour to white. */ + #define ESC_FG_WHITE ANSI_ESCAPE_SEQUENCE("37m") + + /** Sets the foreground (text) colour to the terminal's default. */ + #define ESC_FG_DEFAULT ANSI_ESCAPE_SEQUENCE("39m") + + /** Sets the text background colour to black. */ + #define ESC_BG_BLACK ANSI_ESCAPE_SEQUENCE("40m") + + /** Sets the text background colour to red. */ + #define ESC_BG_RED ANSI_ESCAPE_SEQUENCE("41m") + + /** Sets the text background colour to green. */ + #define ESC_BG_GREEN ANSI_ESCAPE_SEQUENCE("42m") + + /** Sets the text background colour to yellow. */ + #define ESC_BG_YELLOW ANSI_ESCAPE_SEQUENCE("43m") + + /** Sets the text background colour to blue. */ + #define ESC_BG_BLUE ANSI_ESCAPE_SEQUENCE("44m") + + /** Sets the text background colour to magenta. */ + #define ESC_BG_MAGENTA ANSI_ESCAPE_SEQUENCE("45m") + + /** Sets the text background colour to cyan. */ + #define ESC_BG_CYAN ANSI_ESCAPE_SEQUENCE("46m") + + /** Sets the text background colour to white. */ + #define ESC_BG_WHITE ANSI_ESCAPE_SEQUENCE("47m") + + /** Sets the text background colour to the terminal's default. */ + #define ESC_BG_DEFAULT ANSI_ESCAPE_SEQUENCE("49m") + + /** Sets the cursor position to the given line and column. */ + #define ESC_CURSOR_POS(L, C) ANSI_ESCAPE_SEQUENCE(#L ";" #C "H") + + /** Moves the cursor up the given number of lines. */ + #define ESC_CURSOR_UP(L) ANSI_ESCAPE_SEQUENCE(#L "A") + + /** Moves the cursor down the given number of lines. */ + #define ESC_CURSOR_DOWN(L) ANSI_ESCAPE_SEQUENCE(#L "B") + + /** Moves the cursor to the right the given number of columns. */ + #define ESC_CURSOR_FORWARD(C) ANSI_ESCAPE_SEQUENCE(#C "C") + + /** Moves the cursor to the left the given number of columns. */ + #define ESC_CURSOR_BACKWARD(C) ANSI_ESCAPE_SEQUENCE(#C "D") + + /** Saves the current cursor position so that it may be restored with ESC_CURSOR_POS_RESTORE. */ + #define ESC_CURSOR_POS_SAVE ANSI_ESCAPE_SEQUENCE("s") + + /** Restores the cursor position to the last position saved with ESC_CURSOR_POS_SAVE. */ + #define ESC_CURSOR_POS_RESTORE ANSI_ESCAPE_SEQUENCE("u") + + /** Erases the entire display, returning the cursor to the top left. */ + #define ESC_ERASE_DISPLAY ANSI_ESCAPE_SEQUENCE("2J") + + /** Erases the current line, returning the cursor to the far left. */ + #define ESC_ERASE_LINE ANSI_ESCAPE_SEQUENCE("K") + +#endif diff --git a/LUFA/Drivers/USB/Class/ConfigDescriptor.c b/LUFA/Drivers/USB/Class/ConfigDescriptor.c new file mode 100644 index 0000000000..d79106916f --- /dev/null +++ b/LUFA/Drivers/USB/Class/ConfigDescriptor.c @@ -0,0 +1,138 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "ConfigDescriptor.h" + +uint8_t USB_Host_GetDeviceConfigDescriptor(uint16_t* const ConfigSizePtr, void* BufferPtr) +{ + uint8_t ErrorCode; + + USB_HostRequest = (USB_Host_Request_Header_t) + { + bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE), + bRequest: REQ_GetDescriptor, + wValue: (DTYPE_Configuration << 8), + wIndex: 0, + wLength: sizeof(USB_Descriptor_Configuration_Header_t), + }; + + if (BufferPtr == NULL) + { + uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)]; + + ErrorCode = USB_Host_SendControlRequest(ConfigHeader); + + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) + *ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).TotalConfigurationSize; + #else + *ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).wTotalLength; + #endif + } + else + { + USB_HostRequest.wLength = *ConfigSizePtr; + + ErrorCode = USB_Host_SendControlRequest(BufferPtr); + } + + return ErrorCode; +} + +void USB_Host_GetNextDescriptorOfType(uint16_t* const BytesRem, + uint8_t** const CurrConfigLoc, + const uint8_t Type) +{ + while (*BytesRem) + { + USB_Host_GetNextDescriptor(BytesRem, CurrConfigLoc); + + if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type) + return; + } +} + +void USB_Host_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem, + uint8_t** const CurrConfigLoc, + const uint8_t Type, + const uint8_t BeforeType) +{ + while (*BytesRem) + { + USB_Host_GetNextDescriptor(BytesRem, CurrConfigLoc); + + if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type) + { + return; + } + else if (DESCRIPTOR_TYPE(*CurrConfigLoc) == BeforeType) + { + *BytesRem = 0; + return; + } + } +} + +void USB_Host_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem, + uint8_t** const CurrConfigLoc, + const uint8_t Type, + const uint8_t AfterType) +{ + USB_Host_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, AfterType); + + if (*BytesRem) + USB_Host_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type); +} + +uint8_t USB_Host_GetNextDescriptorComp_P(uint16_t* BytesRem, uint8_t** CurrConfigLoc, + uint8_t (* const ComparatorRoutine)(void*)) +{ + uint8_t ErrorCode; + + while (*BytesRem) + { + uint8_t* PrevDescLoc = *CurrConfigLoc; + uint16_t PrevBytesRem = *BytesRem; + + USB_Host_GetNextDescriptor(BytesRem, CurrConfigLoc); + + if ((ErrorCode = ComparatorRoutine(*CurrConfigLoc)) != Descriptor_Search_NotFound) + { + if (ErrorCode == Descriptor_Search_Fail) + { + *CurrConfigLoc = PrevDescLoc; + *BytesRem = PrevBytesRem; + } + + return ErrorCode; + } + } + + return Descriptor_Search_Comp_EndOfDescriptor; +} diff --git a/LUFA/Drivers/USB/Class/ConfigDescriptor.h b/LUFA/Drivers/USB/Class/ConfigDescriptor.h new file mode 100644 index 0000000000..d1f8927f8f --- /dev/null +++ b/LUFA/Drivers/USB/Class/ConfigDescriptor.h @@ -0,0 +1,258 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Configuration descriptor parser API. This section of the library gives a friendly API which can be used in + * host applications to easily parse an attached device's configuration descriptor so that endpoint, interface + * and other descriptor data can be extracted and used as needed. + */ + +#ifndef __CONFIGDESCRIPTOR_H__ +#define __CONFIGDESCRIPTOR_H__ + + /* Includes: */ + #include + + #include "../../../Common/Common.h" + #include "../LowLevel/HostChapter9.h" + #include "../HighLevel/StdDescriptors.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Casts a pointer to a descriptor inside the configuration descriptor into a pointer to the given + * descriptor type. + * + * Usage Example: + * \code + * uint8_t* CurrDescriptor = &ConfigDescriptor[0]; // Pointing to the configuration header + * USB_Descriptor_Configuration_Header_t* ConfigHeaderPtr = DESCRIPTOR_PCAST(CurrDescriptor, + * USB_Descriptor_Configuration_Header_t); + * + * // Can now access elements of the configuration header struct using the -> indirection operator + * \endcode + */ + #define DESCRIPTOR_PCAST(DescriptorPtr, Type) ((Type*)DescriptorPtr) + + /** Casts a pointer to a descriptor inside the configuration descriptor into the given descriptor + * type (as an actual struct instance rather than a pointer to a struct). + * + * Usage Example: + * \code + * uint8_t* CurrDescriptor = &ConfigDescriptor[0]; // Pointing to the configuration header + * USB_Descriptor_Configuration_Header_t ConfigHeader = DESCRIPTOR_CAST(CurrDescriptor, + * USB_Descriptor_Configuration_Header_t); + * + * // Can now access elements of the configuration header struct using the . operator + * \endcode + */ + #define DESCRIPTOR_CAST(DescriptorPtr, Type) (*DESCRIPTOR_PCAST(DescriptorPtr, Type)) + + /** Returns the descriptor's type, expressed as the 8-bit type value in the header of the descriptor. + * This value's meaning depends on the descriptor's placement in the descriptor, but standard type + * values can be accessed in the DescriptorTypes_t enum located in USB/HighLevel/StdDescriptors.h. + */ + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + #define DESCRIPTOR_TYPE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).Type + #else + #define DESCRIPTOR_TYPE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).bDescriptorType + #endif + + /** Returns the descriptor's size, expressed as the 8-bit value indicating the number of bytes. */ + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + #define DESCRIPTOR_SIZE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).Size + #else + #define DESCRIPTOR_SIZE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).bLength + #endif + + /** Creates a prototype for or begins a descriptor comparitor routine. Descriptor comparitor routines are + * small search routines which are passed a pointer to the current sub descriptor in the configuration + * descriptor, and which analyse the sub descriptor to determine whether or not it matches the routine's + * search parameters. Comparitor routines provide a powerful way to scan through the config descriptor + * for certain descriptors matching unique criteria. + * + * Comparitor routines are passed in a single pointer named CurrentDescriptor, and should return a value + * of a member of the DSEARCH_Return_ErrorCodes_t enum. + */ + #define DESCRIPTOR_COMPARATOR(name) uint8_t DCOMP_##name (void* const CurrentDescriptor) + + /** Searches for the next descriptor in the given configuration descriptor using a premade comparator + * function. The routine updates the position and remaining configuration descriptor bytes values + * automatically. If a comparator routine fails a search, the descriptor pointer is retreated back + * so that the next descriptor search invocation will start from the descriptor which first caused the + * original search to fail. This behaviour allows for one comparator to be used immediately after another + * has failed, starting the second search from the descriptor which failed the first. + * + * \param DSize Pointer to an int storing the remaining bytes in the configuration descriptor + * \param DPos Pointer to the current position in the configuration descriptor + * \param DSearch Name of the comparitor search function to use on the configuration descriptor + * + * \return Value of one of the members of the DSEARCH_Comp_Return_ErrorCodes_t enum + * + * Usage Example: + * \code + * DESCRIPTOR_COMPARATOR(EndpointSearcher); // Comparator Prototype + * + * DESCRIPTOR_COMPARATOR(EndpointSearcher) + * { + * if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) + * return Descriptor_Search_Found; + * else + * return Descriptor_Search_NotFound; + * } + * + * //... + * // After retrieving configuration descriptor: + * if (USB_Host_GetNextDescriptorComp(&BytesRemaining, &ConfigDescriptorData, EndpointSearcher) == + * Descriptor_Search_Comp_Found) + * { + * // Do something with the endpoint descriptor + * } + * \endcode + */ + #define USB_Host_GetNextDescriptorComp(DSize, DPos, DSearch) \ + USB_Host_GetNextDescriptorComp_P(DSize, DPos, DCOMP_##DSearch) + /* Enums: */ + /** Enum for return values of a descriptor comparator made with DESCRIPTOR_COMPARATOR. */ + enum DSEARCH_Return_ErrorCodes_t + { + Descriptor_Search_Found = 0, /**< Current descriptor matches comparator criteria. */ + Descriptor_Search_Fail = 1, /**< No further descriptor could possibly match criteria, fail the search. */ + Descriptor_Search_NotFound = 2, /**< Current descriptor does not match comparator criteria. */ + }; + + /** Enum for return values of USB_Host_GetNextDescriptorComp() */ + enum DSEARCH_Comp_Return_ErrorCodes_t + { + Descriptor_Search_Comp_Found = 0, /**< Configuration descriptor now points to decriptor which matches + * search criteria of the given comparator function. */ + Descriptor_Search_Comp_Fail = 1, /**< Comparator function returned Descriptor_Search_Fail. */ + Descriptor_Search_Comp_EndOfDescriptor = 2, /**< End of configuration descriptor reached before match found. */ + }; + + /* Function Prototypes: */ + /** Retrieves the configuration descriptor data or size from an attached device via a standard request. + * + * \param ConfigSizePtr Pointer to a uint16_t for either storing or retrieving the configuration + * descriptor size + * + * \param BufferPtr Pointer to the buffer for storing the configuration descriptor data. If this is + * NULL, the size of the configuration descriptor will be retrieved instead and + * placed in the variable pointed to by ConfigSizePtr. If this is non-NULL, the number + * of bytes indicated by ConfigSizePtr of the configuration descriptor will be loaded + * into the buffer + */ + uint8_t USB_Host_GetDeviceConfigDescriptor(uint16_t* const ConfigSizePtr, void* BufferPtr) + ATTR_NON_NULL_PTR_ARG(1); + + /* Inline Functions: */ + /** Skips over the current sub-descriptor inside the configuration descriptor, so that the pointer then + points to the next sub-descriptor. The bytes remaining value is automatically decremented. + * + * \param BytesRem Pointer to the number of bytes remaining of the configuration descriptor + * \param CurrConfigLoc Pointer to the current descriptor inside the configuration descriptor + */ + static inline void USB_Host_GetNextDescriptor(uint16_t* const BytesRem, + uint8_t** const CurrConfigLoc) + ATTR_NON_NULL_PTR_ARG(1, 2); + static inline void USB_Host_GetNextDescriptor(uint16_t* const BytesRem, + uint8_t** const CurrConfigLoc) + { + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) + uint16_t CurrDescriptorSize = DESCRIPTOR_CAST(*CurrConfigLoc, USB_Descriptor_Header_t).Size; + #else + uint16_t CurrDescriptorSize = DESCRIPTOR_CAST(*CurrConfigLoc, USB_Descriptor_Header_t).bLength; + #endif + + *CurrConfigLoc += CurrDescriptorSize; + *BytesRem -= CurrDescriptorSize; + } + + /** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value. + * The bytes remaining value is automatically decremented. + * + * \param BytesRem Pointer to the number of bytes remaining of the configuration descriptor + * \param CurrConfigLoc Pointer to the current descriptor inside the configuration descriptor + * \param Type Descriptor type value to search for + */ + void USB_Host_GetNextDescriptorOfType(uint16_t* const BytesRem, + uint8_t** const CurrConfigLoc, + const uint8_t Type) + ATTR_NON_NULL_PTR_ARG(1, 2); + + /** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value, + * which must come before a descriptor of the second given type value. If the BeforeType type + * descriptor is reached first, the number of bytes remaining to process is set to zero and the + * function exits. The bytes remaining value is automatically decremented. + * + * \param BytesRem Pointer to the number of bytes remaining of the configuration descriptor + * \param CurrConfigLoc Pointer to the current descriptor inside the configuration descriptor + * \param Type Descriptor type value to search for + * \param BeforeType Descriptor type value which must not be reached before the given Type descriptor + */ + void USB_Host_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem, + uint8_t** const CurrConfigLoc, + const uint8_t Type, + const uint8_t BeforeType) + ATTR_NON_NULL_PTR_ARG(1, 2); + + /** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value, + * which must come after a descriptor of the second given type value. The bytes remaining value is + * automatically decremented. + * + * \param BytesRem Pointer to the number of bytes remaining of the configuration descriptor + * \param CurrConfigLoc Pointer to the current descriptor inside the configuration descriptor + * \param Type Descriptor type value to search for + * \param AfterType Descriptor type value which must be reached before the given Type descriptor + */ + void USB_Host_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem, + uint8_t** const CurrConfigLoc, + const uint8_t Type, + const uint8_t AfterType) + ATTR_NON_NULL_PTR_ARG(1, 2); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Function Prototypes: */ + uint8_t USB_Host_GetNextDescriptorComp_P(uint16_t* BytesRem, uint8_t** CurrConfigLoc, + uint8_t (* const ComparatorRoutine)(void* const)); + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/Class/HIDParser.c b/LUFA/Drivers/USB/Class/HIDParser.c new file mode 100644 index 0000000000..35b280b5c4 --- /dev/null +++ b/LUFA/Drivers/USB/Class/HIDParser.c @@ -0,0 +1,326 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "HIDParser.h" + +uint8_t ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID_ReportInfo_t* const ParserData) +{ + HID_StateTable_t StateTable[HID_STATETABLE_STACK_DEPTH]; + HID_StateTable_t* CurrStateTable = &StateTable[0]; + uint16_t UsageStack[HID_USAGE_STACK_DEPTH]; + uint8_t UsageStackSize = 0; + uint16_t BitOffsetIn = 0; + uint16_t BitOffsetOut = 0; +#if defined(HID_ENABLE_FEATURE_PROCESSING) + uint16_t BitOffsetFeature = 0; +#endif + HID_CollectionPath_t* CurrCollectionPath = NULL; + + memset((void*)ParserData, 0x00, sizeof(HID_ReportInfo_t)); + memset((void*)StateTable, 0x00, sizeof(StateTable)); + + while (ReportSize) + { + uint32_t ReportItemData = 0; + + switch (*ReportData & DATA_SIZE_MASK) + { + case DATA_SIZE_4: + ReportItemData = *((uint32_t*)(ReportData + 1)); + break; + case DATA_SIZE_2: + ReportItemData = *((uint16_t*)(ReportData + 1)); + break; + case DATA_SIZE_1: + ReportItemData = *((uint8_t*)(ReportData + 1)); + break; + } + + switch (*ReportData & (TYPE_MASK | TAG_MASK)) + { + case (TYPE_GLOBAL | TAG_GLOBAL_PUSH): + if (CurrStateTable == &StateTable[HID_STATETABLE_STACK_DEPTH]) + return HID_PARSE_HIDStackOverflow; + + memcpy((CurrStateTable - 1), + CurrStateTable, + sizeof(HID_ReportItem_t)); + + CurrStateTable++; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_POP): + if (CurrStateTable == &StateTable[0]) + return HID_PARSE_HIDStackUnderflow; + + CurrStateTable--; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_USAGEPAGE): + CurrStateTable->Attributes.Usage.Page = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMIN): + CurrStateTable->Attributes.Logical.Minimum = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMAX): + CurrStateTable->Attributes.Logical.Maximum = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMIN): + CurrStateTable->Attributes.Physical.Minimum = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMAX): + CurrStateTable->Attributes.Physical.Maximum = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_UNITEXP): + CurrStateTable->Attributes.Unit.Exponent = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_UNIT): + CurrStateTable->Attributes.Unit.Type = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTSIZE): + CurrStateTable->Attributes.BitSize = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTCOUNT): + CurrStateTable->ReportCount = ReportItemData; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID): + CurrStateTable->ReportID = ReportItemData; + break; + case (TYPE_LOCAL | TAG_LOCAL_USAGE): + if (UsageStackSize == HID_USAGE_STACK_DEPTH) + return HID_PARSE_UsageStackOverflow; + + UsageStack[UsageStackSize++] = ReportItemData; + break; + case (TYPE_LOCAL | TAG_LOCAL_USAGEMIN): + CurrStateTable->Attributes.Usage.MinMax.Minimum = ReportItemData; + break; + case (TYPE_LOCAL | TAG_LOCAL_USAGEMAX): + CurrStateTable->Attributes.Usage.MinMax.Maximum = ReportItemData; + break; + case (TYPE_MAIN | TAG_MAIN_COLLECTION): + if (CurrCollectionPath == NULL) + { + CurrCollectionPath = &ParserData->CollectionPaths[0]; + } + else + { + HID_CollectionPath_t* ParentCollectionPath = CurrCollectionPath; + + CurrCollectionPath = &ParserData->CollectionPaths[1]; + + while (CurrCollectionPath->Parent != NULL); + { + if (CurrCollectionPath == &ParserData->CollectionPaths[HID_MAX_COLLECTIONS]) + return HID_PARSE_InsufficientCollectionPaths; + + CurrCollectionPath++; + } + + CurrCollectionPath->Parent = ParentCollectionPath; + } + + CurrCollectionPath->Type = ReportItemData; + CurrCollectionPath->Usage.Page = CurrStateTable->Attributes.Usage.Page; + + if (UsageStackSize) + { + CurrCollectionPath->Usage.Usage = UsageStack[0]; + + for (uint8_t i = 0; i < UsageStackSize; i++) + UsageStack[i] = UsageStack[i + 1]; + + UsageStackSize--; + } + else + { + CurrCollectionPath->Usage.Usage = 0; + } + + break; + case (TYPE_MAIN | TAG_MAIN_ENDCOLLECTION): + if (CurrCollectionPath == NULL) + return HID_PARSE_UnexpectedEndCollection; + + CurrCollectionPath = CurrCollectionPath->Parent; + + break; + case (TYPE_MAIN | TAG_MAIN_INPUT): + case (TYPE_MAIN | TAG_MAIN_OUTPUT): +#if defined(HID_ENABLE_FEATURE_PROCESSING) + case (TYPE_MAIN | TAG_MAIN_FEATURE): +#endif + for (uint8_t ReportItemNum = 0; ReportItemNum < CurrStateTable->ReportCount; ReportItemNum++) + { + HID_ReportItem_t* CurrReportItem = &ParserData->ReportItems[ParserData->TotalReportItems]; + + if (ParserData->TotalReportItems == HID_MAX_REPORTITEMS) + return HID_PARSE_InsufficientReportItems; + + memcpy(&CurrReportItem->Attributes, + &CurrStateTable->Attributes, + sizeof(HID_ReportItem_Attributes_t)); + + CurrReportItem->ItemFlags = ReportItemData; + CurrReportItem->CollectionPath = CurrCollectionPath; + CurrReportItem->ReportID = CurrStateTable->ReportID; + + if (UsageStackSize) + { + CurrReportItem->Attributes.Usage.Usage = UsageStack[0]; + + for (uint8_t i = 0; i < UsageStackSize; i++) + UsageStack[i] = UsageStack[i + 1]; + + UsageStackSize--; + } + else + { + CurrReportItem->Attributes.Usage.Usage = 0; + } + + switch (*ReportData & TAG_MASK) + { + case TAG_MAIN_INPUT: + CurrReportItem->ItemType = REPORT_ITEM_TYPE_In; + CurrReportItem->BitOffset = BitOffsetIn; + + BitOffsetIn += CurrStateTable->Attributes.BitSize; + + break; + case TAG_MAIN_OUTPUT: + CurrReportItem->ItemType = REPORT_ITEM_TYPE_Out; + CurrReportItem->BitOffset = BitOffsetOut; + + BitOffsetOut += CurrStateTable->Attributes.BitSize; + + break; +#if defined(HID_ENABLE_FEATURE_PROCESSING) + case TAG_MAIN_FEATURE: + CurrReportItem->ItemType = REPORT_ITEM_TYPE_Feature; + CurrReportItem->BitOffset = BitOffsetFeature; + + BitOffsetFeature += CurrStateTable->Attributes.BitSize; + + break; +#endif + } + +#if !defined(HID_INCLUDE_CONSTANT_DATA_ITEMS) + if (!(ReportItemData & IOF_CONSTANT)) + ParserData->TotalReportItems++; +#else + ParserData->TotalReportItems++; +#endif + } + + UsageStackSize = 0; + + break; + } + + if ((*ReportData & TYPE_MASK) == TYPE_MAIN) + { + CurrStateTable->Attributes.Usage.MinMax.Minimum = 0; + CurrStateTable->Attributes.Usage.MinMax.Maximum = 0; + UsageStackSize = 0; + } + + switch (*ReportData & DATA_SIZE_MASK) + { + case DATA_SIZE_4: + ReportSize -= 5; + ReportData += 5; + break; + case DATA_SIZE_2: + ReportSize -= 3; + ReportData += 3; + break; + case DATA_SIZE_1: + ReportSize -= 2; + ReportData += 2; + break; + case DATA_SIZE_0: + ReportSize -= 1; + ReportData += 1; + break; + } + } + + return HID_PARSE_Successful; +} + +bool GetReportItemInfo(const uint8_t* ReportData, HID_ReportItem_t* const ReportItem) +{ + uint16_t DataBitsRem = ReportItem->Attributes.BitSize; + uint16_t CurrentBit = ReportItem->BitOffset; + uint32_t BitMask = (1 << 0); + + ReportItem->Value = 0; + + if (ReportItem->ReportID) + { + if (ReportItem->ReportID != ReportData[0]) + return false; + + ReportData++; + } + + while (DataBitsRem--) + { + if (ReportData[CurrentBit / 8] & (1 << (CurrentBit % 8))) + ReportItem->Value |= BitMask; + + CurrentBit++; + BitMask <<= 1; + } + + return true; +} + +void SetReportItemInfo(uint8_t* ReportData, const HID_ReportItem_t* ReportItem) +{ + uint16_t DataBitsRem = ReportItem->Attributes.BitSize; + uint16_t CurrentBit = ReportItem->BitOffset; + uint32_t BitMask = (1 << 0); + + if (ReportItem->ReportID) + { + ReportData[0] = ReportItem->ReportID; + ReportData++; + } + + while (DataBitsRem--) + { + if (ReportItem->Value & (1 << (CurrentBit % 8))) + ReportData[CurrentBit / 8] |= BitMask; + + CurrentBit++; + BitMask <<= 1; + } +} diff --git a/LUFA/Drivers/USB/Class/HIDParser.h b/LUFA/Drivers/USB/Class/HIDParser.h new file mode 100644 index 0000000000..314d080729 --- /dev/null +++ b/LUFA/Drivers/USB/Class/HIDParser.h @@ -0,0 +1,252 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * USB Human Interface Device (HID) Class report descriptor processing routines. This file allows for the easy + * parsing of the complex HID report descriptor, which describes the data that the device transmits to the host. + * + * The processed report is presented back to the user application as a flat structure containing each report + * item's IN, OUT and FEATURE (if desired) items along with each item's attributes. + * + * This library portion also allows for easy setting and retrieval of data from a HID report, including devices + * with multiple reports on the one HID interface. + * + * By default, FEATURE reports and IN/OUT reports with constant data are ignored in the HID report when processed + * to save on memory. This can be overridden by defining the HID_ENABLE_FEATURE_PROCESSING or + * HID_INCLUDE_CONSTANT_DATA_ITEMS tokens in the user project makefile, passing them to the compiler via the -D + * switch. + */ + +#ifndef __HIDPARSER_H__ +#define __HIDPARSER_H__ + + /* Includes: */ + #include + #include + + #include "HIDReportData.h" + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor checks and defines: */ + #if !defined(HID_STATETABLE_STACK_DEPTH) || defined(__DOXYGEN__) + /** Constant indicating the maximum stack depth of the state table. A larger state table + * allows for more PUSH/POP report items to be nested, but consumes more memory. By default + * this is set to 3 levels (allowing for two PUSHes to be nested) but this can be overridden by + * defining HID_STATETABLE_STACK_DEPTH to another value in the user project makefile, passing the + * define to the compiler using the -D compiler switch. + */ + #define HID_STATETABLE_STACK_DEPTH 3 + #endif + + #if !defined(HID_USAGE_STACK_DEPTH) || defined(__DOXYGEN__) + /** Constant indicating the maximum stack depth of the usage table. A larger usage table + * allows for more USAGE items to be indicated sequentially for REPORT COUNT entries of more than + * one, but requires more stack space. By default this is set to 8 levels (allowing for a report + * item with a count of 8) but this can be overridden by defining HID_USAGE_STACK_DEPTH to another + * value in the user project makefile, passing the define to the compiler using the -D compiler + * switch. + */ + #define HID_USAGE_STACK_DEPTH 8 + #endif + + #if !defined(HID_MAX_COLLECTIONS) || defined(__DOXYGEN__) + /** Constant indicating the maximum number of COLLECTION items (nested or unnested) that can be + * processed in the report item descriptor. A large value allows for more COLLECTION items to be + * processed, but consumes more memory. By default this is set to 5 collections, but this can be + * overridden by defining HID_MAX_COLLECTIONS to another value in the user project makefile, passing + * the define to the compiler using the -D compiler switch. + */ + #define HID_MAX_COLLECTIONS 5 + #endif + + #if !defined(HID_MAX_REPORTITEMS) || defined(__DOXYGEN__) + /** Constant indicating the maximum number of report items (IN, OUT or FEATURE if enabled) that can be + * processed in the report item descriptor. A large value allows for more report items to be + * processed, but consumes more memory. By default this is set to 30 items, but this can be + * overridden by defining HID_MAX_REPORTITEMS to another value in the user project makefile, passing + * the define to the compiler using the -D compiler switch. + */ + #define HID_MAX_REPORTITEMS 30 + #endif + + /* Public Interface - May be used in end-application: */ + /* Enums: */ + /** Enum for indicating what type of report item an entry in a HID_ReportInfo_t ReportItem array is */ + enum HID_ReportItemTypes_t + { + REPORT_ITEM_TYPE_In = 0, /**< Indicates that the item is an IN report type. */ + REPORT_ITEM_TYPE_Out = 1, /**< Indicates that the item is an OUT report type. */ + REPORT_ITEM_TYPE_Feature = 2, /**< Indicates that the item is a FEATURE report type. */ + }; + + /** Enum for the possible error codes in the return value of the ProcessHIDReport() function */ + enum HID_Parse_ErrorCodes_t + { + HID_PARSE_Successful = 0, /**< Successful parse of the HID report descriptor, no error. */ + HID_PARSE_HIDStackOverflow = 1, /**< More than HID_STATETABLE_STACK_DEPTH nested PUSHes in the report. */ + HID_PARSE_HIDStackUnderflow = 2, /**< A POP was found when the state table stack was empty. */ + HID_PARSE_InsufficientReportItems = 3, /**< More than HID_MAX_REPORTITEMS report items in the report. */ + HID_PARSE_UnexpectedEndCollection = 4, /**< END COLLECTION found without matching COLLECTION item. */ + HID_PARSE_InsufficientCollectionPaths = 5, /**< More than HID_MAX_COLLECTIONS collections in the report. */ + HID_PARSE_UsageStackOverflow = 6, /**< More than HID_USAGE_STACK_DEPTH usages listed in a row. */ + }; + + /* Type Defines: */ + /** Type define for an attribute with both minimum and maximum values (e.g. Logical Min/Max). */ + typedef struct + { + uint32_t Minimum; /**< Minimum value for the attribute. */ + uint32_t Maximum; /**< Maximum value for the attribute. */ + } HID_MinMax_t; + + /** Type define for the Unit attributes of a report item. */ + typedef struct + { + uint32_t Type; /**< Unit type (refer to HID specifications for details). */ + uint8_t Exponent; /**< Unit exponent (refer to HID specifications for details). */ + } HID_Unit_t; + + /** Type define for the Usage attributes of a report item. */ + typedef struct + { + uint16_t Page; /**< Usage page of the report item. */ + uint16_t Usage; /**< Usage of the report item. */ + HID_MinMax_t MinMax; /**< Usage minimum and maximum of the report item. */ + } HID_Usage_t; + + /** Type define for a COLLECTION object. Contains the collection attributes and a reference to the + * parent collection if any. + */ + typedef struct CollectionPath + { + uint8_t Type; /**< Collection type (for example "Generic Desktop"). */ + HID_Usage_t Usage; /**< Collection usage. */ + struct CollectionPath* Parent; /**< Reference to parent collection, or NULL if root collection. */ + } HID_CollectionPath_t; + + /** Type define for all the data attributes of a report item, except flags. */ + typedef struct + { + uint8_t BitSize; /**< Size in bits of the report item's data. */ + + HID_Usage_t Usage; /**< Usage of the report item. */ + HID_Unit_t Unit; /**< Unit type and exponent of the report item. */ + HID_MinMax_t Logical; /**< Logical minimum and maximum of the report item. */ + HID_MinMax_t Physical; /**< Physical minimum and maximum of the report item. */ + } HID_ReportItem_Attributes_t; + + /** Type define for a report item (IN, OUT or FEATURE) attributes and other details. */ + typedef struct + { + uint16_t BitOffset; /**< Bit offset in the IN, OUT or FEATURE report of the item. */ + uint8_t ItemType; /**< Report item type, a value in HID_Types_t. */ + uint16_t ItemFlags; /**< Item data flags, such as constant/variable, etc. */ + uint8_t ReportID; /**< Report ID this item belongs to, or 0x00 if device has only one report */ + HID_CollectionPath_t* CollectionPath; /**< Collection path of the item. */ + + HID_ReportItem_Attributes_t Attributes; /**< Report item attributes. */ + + uint32_t Value; /**< Current value of the report item. */ + } HID_ReportItem_t; + + /** Type define for a complete processed HID report, including all report item data and collections. */ + typedef struct + { + uint8_t TotalReportItems; /**< Total number of report items stored in the + * ReportItems array. */ + + HID_ReportItem_t ReportItems[HID_MAX_REPORTITEMS]; /**< Report items array, including + * all IN, OUT and FEATURE items. */ + + HID_CollectionPath_t CollectionPaths[HID_MAX_COLLECTIONS]; /**< All collection items, referenced + * by the report items. */ + } HID_ReportInfo_t; + + /* Function Prototypes: */ + /** Function to process a given HID report returned from an attached device, and store it into a given + * HID_ReportInfo_t structure. + * + * \param ReportData Buffer containing the device's HID report table + * \param ReportSize Size in bytes of the HID report table + * \param ParserData Pointer to a HID_ReportInfo_t instance for the parser output + * + * \return A value in the HID_Parse_ErrorCodes_t enum + */ + uint8_t ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID_ReportInfo_t* const ParserData) + ATTR_NON_NULL_PTR_ARG(1, 3); + + /** Extracts the given report item's value out of the given HID report and places it into the Value + * member of the report item's HID_ReportItem_t structure. + * + * \param ReportData Buffer containing an IN or FEATURE report from an attached device + * \param ReportItem Pointer to the report item of interest in a HID_ReportInfo_t ReportItem array + * + * \returns Boolean true if the item to retrieve was located in the given report, false otherwise + */ + bool GetReportItemInfo(const uint8_t* ReportData, HID_ReportItem_t* const ReportItem) + ATTR_NON_NULL_PTR_ARG(1, 2); + + /** Retreives the given report item's value out of the Value member of the report item's + * HID_ReportItem_t structure and places it into the correct position in the HID report + * buffer. The report buffer is assumed to have the appropriate bits cleared before calling + * this function (i.e., the buffer should be explicitly cleared before report values are added). + * + * If the device has multiple HID reports, the report ID is set to the report ID of the given item. + * + * \param ReportData Buffer holding the current OUT report data + * \param ReportItem Pointer to the report item of interest in a HID_ReportInfo_t ReportItem array + */ + void SetReportItemInfo(uint8_t* ReportData, const HID_ReportItem_t* ReportItem) + ATTR_NON_NULL_PTR_ARG(1, 2); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Type Defines: */ + typedef struct + { + HID_ReportItem_Attributes_t Attributes; + uint8_t ReportCount; + uint8_t ReportID; + } HID_StateTable_t; + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/Class/HIDReportData.h b/LUFA/Drivers/USB/Class/HIDReportData.h new file mode 100644 index 0000000000..1bb8676d7f --- /dev/null +++ b/LUFA/Drivers/USB/Class/HIDReportData.h @@ -0,0 +1,128 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Constants for HID report item attributes. Refer to the HID specification for details on each + * flag's meaning when applied to an IN, OUT or FEATURE item. + */ + +#ifndef __HIDREPORTDATA_H__ +#define __HIDREPORTDATA_H__ + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** HID_ReportItem_t.ItemFlags flag for constant data. */ + #define IOF_CONSTANT (1 << 0) + + /** HID_ReportItem_t.ItemFlags flag for data. */ + #define IOF_DATA (0 << 0) + + /** HID_ReportItem_t.ItemFlags flag for variable data. */ + #define IOF_VARIABLE (1 << 1) + + /** HID_ReportItem_t.ItemFlags flag for array data. */ + #define IOF_ARRAY (0 << 1) + + /** HID_ReportItem_t.ItemFlags flag for relative data. */ + #define IOF_RELATIVE (1 << 2) + + /** HID_ReportItem_t.ItemFlags flag for absolute data. */ + #define IOF_ABSOLUTE (0 << 2) + + /** HID_ReportItem_t.ItemFlags flag for wrapped value data. */ + #define IOF_WRAP (1 << 3) + + /** HID_ReportItem_t.ItemFlags flag for non-wrapped value data. */ + #define IOF_NOWRAP (0 << 3) + + /** HID_ReportItem_t.ItemFlags flag for non linear data. */ + #define IOF_NONLINEAR (1 << 4) + + /** HID_ReportItem_t.ItemFlags flag for linear data. */ + #define IOF_LINEAR (0 << 4) + + /** HID_ReportItem_t.ItemFlags flag for no preferred state. */ + #define IOF_NOPREFERRED (1 << 5) + + /** HID_ReportItem_t.ItemFlags flag for preferred state items. */ + #define IOF_PREFERREDSTATE (0 << 5) + + /** HID_ReportItem_t.ItemFlags flag for null state items. */ + #define IOF_NULLSTATE (1 << 6) + + /** HID_ReportItem_t.ItemFlags flag for no null position data. */ + #define IOF_NONULLPOSITION (0 << 6) + + /** HID_ReportItem_t.ItemFlags flag for buffered bytes. */ + #define IOF_BUFFEREDBYTES (1 << 8) + + /** HID_ReportItem_t.ItemFlags flag for bitfield data. */ + #define IOF_BITFIELD (0 << 8) + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define DATA_SIZE_MASK 0b00000011 + #define TYPE_MASK 0b00001100 + #define TAG_MASK 0b11110000 + + #define DATA_SIZE_0 0b00000000 + #define DATA_SIZE_1 0b00000001 + #define DATA_SIZE_2 0b00000010 + #define DATA_SIZE_4 0b00000011 + + #define TYPE_MAIN 0b00000000 + #define TYPE_GLOBAL 0b00000100 + #define TYPE_LOCAL 0b00001000 + + #define TAG_MAIN_INPUT 0b10000000 + #define TAG_MAIN_OUTPUT 0b10010000 + #define TAG_MAIN_COLLECTION 0b10100000 + #define TAG_MAIN_FEATURE 0b10110000 + #define TAG_MAIN_ENDCOLLECTION 0b11000000 + #define TAG_GLOBAL_USAGEPAGE 0b00000000 + #define TAG_GLOBAL_LOGICALMIN 0b00010000 + #define TAG_GLOBAL_LOGICALMAX 0b00100000 + #define TAG_GLOBAL_PHYSMIN 0b00110000 + #define TAG_GLOBAL_PHYSMAX 0b01000000 + #define TAG_GLOBAL_UNITEXP 0b01010000 + #define TAG_GLOBAL_UNIT 0b01100000 + #define TAG_GLOBAL_REPORTSIZE 0b01110000 + #define TAG_GLOBAL_REPORTID 0b10000000 + #define TAG_GLOBAL_REPORTCOUNT 0b10010000 + #define TAG_GLOBAL_PUSH 0b10100000 + #define TAG_GLOBAL_POP 0b10110000 + #define TAG_LOCAL_USAGE 0b00000000 + #define TAG_LOCAL_USAGEMIN 0b00010000 + #define TAG_LOCAL_USAGEMAX 0b00100000 + #endif + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/Events.c b/LUFA/Drivers/USB/HighLevel/Events.c new file mode 100644 index 0000000000..dbc428aaeb --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/Events.c @@ -0,0 +1,39 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "../LowLevel/USBMode.h" + +#define INCLUDE_FROM_EVENTS_C +#include "Events.h" + +void USB_Event_Stub(void) +{ + +} diff --git a/LUFA/Drivers/USB/HighLevel/Events.h b/LUFA/Drivers/USB/HighLevel/Events.h new file mode 100644 index 0000000000..eeb0ed37ad --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/Events.h @@ -0,0 +1,440 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +/** Library events module. This module contains macros and functions relating to the management of library + * events, which are small pieces of code similar to ISRs which are run when a given condition is met. Each + * event can be fired from multiple places in the user or library code, which may or may not be inside an ISR, + * thus each handler should be written to be as small and fast as possible to prevent possible problems. + * + * Events can be hooked by the user application using the EVENT_HANDLER() and HANDLES_EVENT() macros. If an + * event with no associated handler is fired within the library, it by default fires an internal empty stub + * function. This is achieved through the use of the GCC compiler's "alias" attribute. + * + * Each event must only have one associated event handler, but can be raised by multiple sources. + */ + +#ifndef __USBEVENTS_H__ +#define __USBEVENTS_H__ + + /* Includes: */ + #include + + #include "../../../Common/Common.h" + #include "../LowLevel/USBMode.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Raises a given event name, with the specified parameters. For events with no parameters the + * only argument to the macro is the event name, events with parameters list the parameter values + * after the name as a comma seperated list. + * + * When a given event is fired, its corresponding event handler code is executed. + * + * Usage Examples: + * \code + * // Raise the USB_VBUSChange event, which takes no parameters + * RAISE_EVENT(USB_VBUSChange); + * + * // Raise the USB_UnhandledControlPacket event which takes two parameters + * RAISE_EVENT(USB_UnhandledControlPacket, 0, 1); + * \endcode + * + * \see RAISES_EVENT() + */ + #define RAISE_EVENT(e, ...) Event_ ## e (__VA_ARGS__) + + /** Indicates that a given module can raise a given event. This is the equivelent of putting the + * event function's prototype into the module, but in a cleaner way. Each event which may be + * fired via the RAISE_EVENT macro in the module should have an accompanying RAISES_EVENT + * prototype in the module's header file. + * + * Usage Examples: + * \code + * // Module can raise the USB_VBUSChange event + * RAISES_EVENT(USB_VBUSChange); + * + * // ... + * // Inside a block of code in a function of the module, raise the USB_VBUSChange event + * RAISE_EVENT(USB_VBUSChange); + * \endcode + * + * \see RAISE_EVENT() + */ + #define RAISES_EVENT(e) HANDLES_EVENT(e) + + /** Defines an event handler for the given event. Event handlers should be short in length, as they + * may be raised from inside an ISR. The user application can react to each event as it sees fit, + * such as logging the event, indicating the change to the user or performing some other action. + * + * Only one event handler may be defined in any user project for each individual event. Events may + * or may not have parameters - for each event, refer to its documentation elsewhere in this module + * to determine the presense and purpose of any event parameters. + * + * Usage Example: + * \code + * // Create an event handler for the USB_VBUSChange event + * EVENT_HANDLER(USB_VBUSChange) + * { + * // Code to execute when the VBUS level changes + * } + * \endcode + * + * \see HANDLES_EVENT() + */ + #define EVENT_HANDLER(e) void Event_ ## e e ## _P + + /** Indicates that a given module handles an event. This is the equivelent of putting the + * event function's prototype into the module, but in a cleaner way. Each event which may be + * handled via the EVENT_HANDLER macro in the module should have an accompanying HANDLES_EVENT + * prototype in the module's header file. + * + * Usage Examples: + * \code + * // Module handles the USB_VBUSChange event + * HANDLES_EVENT(USB_VBUSChange); + * + * // Create the USB_VBUSChange event handler + * EVENT_HANDLER(USB_VBUSChange) + * { + * // Event handler code here + * } + * \endcode + * + * \see EVENT_HANDLER() + */ + #define HANDLES_EVENT(e) EVENT_HANDLER(e) + + /* Psudo-Functions for Doxygen: */ + #if defined(__DOXYGEN__) + /** Event for VBUS level change. This event fires when the VBUS line of the USB AVR changes from + * high to low or vice-versa. + * + * \note This event is only available on USB AVR models which support VBUS notification interrupts. + */ + void USB_VBUSChange(void); + + /** Event for VBUS attachment. This event fires when the VBUS line of the USB AVR changes from + * low to high, signalling the attachment of the USB device to a host, before the enumeration + * process has begun. + * + * \note This event is only available on USB AVR models which support VBUS notification interrupts. + */ + void USB_VBUSConnect(void); + + /** Event for VBUS detachment. This event fires when the VBUS line of the USB AVR changes from + * high to low, signalling the USB device has been removed from a host whether it has been enumerated + * or not. + * + * \note This event is only available on USB AVR models which support VBUS notification interrupts. + */ + void USB_VBUSDisconnect(void); + + /** Event for USB device connection. This event fires when the AVR is in USB host mode and a device + * has been attached (but not yet fully enumerated), or when in device mode and the device is connected + * to a host, beginning the enumeration process. + * + * When in device mode, this can be used to progmatically start the USB management task to reduce + * CPU usage. + * + * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller. + * this means that the current connection state is derived from the bus suspension and wake up events by default, + * which is not always accurate (host may suspend the bus while still connected). If the actual connection state + * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by + * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection + * and disconnection events may be manually fired by RAISE_EVENT(), and the USB_IsConnected global changed manually. + * + * \see USBTask.h for more information on the USB management task and reducing CPU usage. + */ + void USB_Connect(void); + + /** Event for USB device disconnection. This event fires when the AVR is in USB host mode and an + * attached and enumerated device has been disconnected, or when in device mode and the device is + * disconnected from the host. + * + * When in device mode, this can be used to progmatically stop the USB management task to reduce + * CPU usage. + * + * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller. + * this means that the current connection state is derived from the bus suspension and wake up events by default, + * which is not always accurate (host may suspend the bus while still connected). If the actual connection state + * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by + * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection + * and disconnection events may be manually fired by RAISE_EVENT(), and the USB_IsConnected global changed manually. + * + * \see USBTask.h for more information on the USB management task and reducing CPU usage. + */ + void USB_Disconnect(void); + + /** Event for USB device power on failure. This event fires when the USB interface fails to + * initialize correctly due to a hardware or software fault. + * + * \param ErrorCode Error code indicating the failure reason, a value in USB_PowerOnErrorCodes_t + * located in LowLevel.h. + */ + void USB_PowerOnFail(const uint8_t ErrorCode); + + /** Event for USB mode pin level change. This event fires when the USB interface is set to dual role + * mode, and the UID pin level has changed to indicate a new mode (device or host). This event fires + * before the mode is switched to the newly indicated mode. + * + * \note This event only exists on USB AVR models which support dual role modes. + * + * \note This event does not exist if the USB_DEVICE_ONLY or USB_HOST_ONLY tokens have been supplied + * to the compiler (see LowLevel.h documentation). + */ + void USB_UIDChange(void); + + /** Event for USB host error. This event fires when a hardware fault has occurred whilst the USB + * interface is in host mode. + * + * \param ErrorCode Error code indicating the failure reason, a value in USB_Host_ErrorCodes_t + * located in Host.h. + * + * \note This event only exists on USB AVR models which supports host mode. + * + * \note This event does not exist if the USB_DEVICE_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + */ + void USB_HostError(const uint8_t ErrorCode); + + /** Event for USB device attachment. This event fires when a the USB interface is in host mode, and + * a USB device has been connected to the USB interface. This is interrupt driven, thus fires before + * the standard USB_DeviceConnect event and so can be used to programatically start the USB management + * task to reduce CPU consumption. + * + * \note This event only exists on USB AVR models which supports host mode. + * + * \note This event does not exist if the USB_DEVICE_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + * + * \see USBTask.h for more information on the USB management task and reducing CPU usage. + */ + void USB_DeviceAttached(void); + + /** Event for USB device removal. This event fires when a the USB interface is in host mode, and + * a USB device has been removed the USB interface whether or not it has been enumerated. This + * can be used to programatically stop the USB management task to reduce CPU consumption. + * + * \note This event only exists on USB AVR models which supports host mode. + * + * \note This event does not exist if the USB_DEVICE_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + * + * \see USBTask.h for more information on the USB management task and reducing CPU usage. + */ + void USB_DeviceUnattached(void); + + /** Event for USB device enumeration failure. This event fires when a the USB interface is + * in host mode, and an attached USB device has failed to enumerate completely. + * + * \param ErrorCode Error code indicating the failure reason, a value in + * USB_Host_EnumerationErrorCodes_t located in Host.h. + * + * \param SubErrorCode Sub error code indicating the reason for failure - for example, if the + * ErrorCode parameter indicates a control error, this will give the error + * code returned by the USB_Host_SendControlRequest() function. + * + * \note This event only exists on USB AVR models which supports host mode. + * + * \note This event does not exist if the USB_DEVICE_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + */ + void USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode); + + /** Event for USB device enumeration completion. This event fires when a the USB interface is + * in host mode and an attached USB device has been completely enumerated and is ready to be + * controlled by the user application, or when the library is in device mode, and the Host + * has finished enumerating the device. + */ + void USB_DeviceEnumerationComplete(void); + + /** Event for unhandled control requests. This event fires when a the USB host issues a control + * request to the control endpoint (address 0) that the library does not handle. This may either + * be a standard request that the library has no handler code for, or a class specific request + * issued to the device which must be handled appropriately. Due to the strict timing requirements + * on control transfers, interrupts are disabled during control request processing. + * + * \param bRequest Request value, indicating what command the host has issued. + * \param bmRequestType Mask indicating the request data direction (if any), type and recipient. + * + * \note This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + * + * \note Requests should be handled in the same manner as described in the USB 2.0 Specification, + * or appropriate class' specification. In all instances, the library has already read the + * request bmRequestType and bRequest values out (into the Request and RequestType parameters + * respectively) so that it can correctly determine if it is able to handle the request + * internally, or hand off the request to the user application via this event. Other request + * parameters (wValue, wIndex, wLength, and Data) remain in the control endpoint bank until + * read out by the user application for processing. + */ + void USB_UnhandledControlPacket(const uint8_t bRequest, const uint8_t bmRequestType); + + /** Event for USB configuration number changed. This event fires when a the USB host changes the + * selected configuration number while in device mode. This event should be hooked in device + * applications to create the endpoints and configure the device for the selected configuration. + * + * This event fires after the value of USB_ConfigurationNumber has been changed. + * + * \note This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + */ + void USB_ConfigurationChanged(void); + + /** Event for USB suspend. This event fires when a the USB host suspends the device by halting its + * transmission of Start Of Frame pulses to the device. This is generally hooked in order to move + * the device over to a low power state until the host wakes up the device. + * + * \note This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + * + * \see USB_WakeUp() event for accompanying Wake Up event. + */ + void USB_Suspend(void); + + /** Event for USB wake up. This event fires when a the USB interface is suspended while in device + * mode, and the host wakes up the device by supplying Start Of Frame pulses. This is generally + * hooked to pull the user application out of a lowe power state and back into normal operating + * mode. + * + * \note This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + * + * \see USB_Suspend() event for accompanying Suspend event. + */ + void USB_WakeUp(void); + + /** Event for USB interface reset. This event fires when a the USB interface is in device mode, and + * a the USB host requests that the device reset its interface. This is generally hooked so that + * the USB control endpoint can be switched to interrupt driven mode, by selecting it and calling + * USB_INT_Enable(ENDPOINT_INT_SETUP). Before this event fires, all device endpoints are reset and + * disabled. + * + * \note This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + */ + void USB_Reset(void); + + /** Event for USB device mode error. This event fires when the USB interface is in device mode, + * and an error occurs which prevents it from operating normally. + * + * \param ErrorCode Error code indicating the source of the error. One of the values in the + * USB_Device_ErrorCodes_t enum located in Device.h. + * + * \note This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see + * LowLevel.h documentation). + */ + void USB_DeviceError(const uint8_t ErrorCode); + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define ALIAS_STUB(e) EVENT_HANDLER(e) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub) + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) + #define USB_VBUSChange_P (void) + #define USB_VBUSConnect_P (void) + #define USB_VBUSDisconnect_P (void) + #endif + + #define USB_Connect_P (void) + #define USB_Disconnect_P (void) + #define USB_DeviceEnumerationComplete_P (void) + + #if defined(USB_CAN_BE_BOTH) + #define USB_PowerOnFail_P (const uint8_t ErrorCode) + #define USB_UIDChange_P (void) + #endif + + #if defined(USB_CAN_BE_HOST) + #define USB_HostError_P (const uint8_t ErrorCode) + #define USB_DeviceAttached_P (void) + #define USB_DeviceUnattached_P (void) + #define USB_DeviceEnumerationFailed_P (const uint8_t ErrorCode, const uint8_t SubErrorCode) + #endif + + #if defined(USB_CAN_BE_DEVICE) + #define USB_UnhandledControlPacket_P (const uint8_t bRequest, const uint8_t bmRequestType) + #define USB_ConfigurationChanged_P (void) + #define USB_Suspend_P (void) + #define USB_WakeUp_P (void) + #define USB_Reset_P (void) + #define USB_DeviceError_P (const uint8_t ErrorCode) + #endif + + /* Function Prototypes: */ + #if defined(INCLUDE_FROM_EVENTS_C) + void USB_Event_Stub (void) ATTR_CONST; + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) + ALIAS_STUB(USB_VBUSChange); + ALIAS_STUB(USB_VBUSConnect); + ALIAS_STUB(USB_VBUSDisconnect); + #endif + + ALIAS_STUB(USB_Connect); + ALIAS_STUB(USB_Disconnect); + ALIAS_STUB(USB_DeviceEnumerationComplete); + + #if defined(USB_CAN_BE_BOTH) + ALIAS_STUB(USB_PowerOnFail); + ALIAS_STUB(USB_UIDChange); + #endif + + #if defined(USB_CAN_BE_HOST) + ALIAS_STUB(USB_HostError); + ALIAS_STUB(USB_DeviceAttached); + ALIAS_STUB(USB_DeviceUnattached); + ALIAS_STUB(USB_DeviceEnumerationFailed); + #endif + + #if defined(USB_CAN_BE_DEVICE) + ALIAS_STUB(USB_UnhandledControlPacket); + ALIAS_STUB(USB_ConfigurationChanged); + ALIAS_STUB(USB_Suspend); + ALIAS_STUB(USB_WakeUp); + ALIAS_STUB(USB_Reset); + ALIAS_STUB(USB_DeviceError); + #endif + #endif + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/StdDescriptors.c b/LUFA/Drivers/USB/HighLevel/StdDescriptors.c new file mode 100644 index 0000000000..5fdc72e809 --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/StdDescriptors.c @@ -0,0 +1,43 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "../LowLevel/USBMode.h" +#if defined(USB_CAN_BE_DEVICE) + +#include "StdDescriptors.h" + +uint16_t USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress) +{ + RAISE_EVENT(USB_DeviceError, DEVICE_ERROR_GetDescriptorNotHooked); + + return 0; +}; + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/StdDescriptors.h b/LUFA/Drivers/USB/HighLevel/StdDescriptors.h new file mode 100644 index 0000000000..d9075cc755 --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/StdDescriptors.h @@ -0,0 +1,523 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Standard USB device descriptor defines and retrieval routines, for USB devices. This module contains + * strucutures and macros for the easy creation of standard USB descriptors in USB device projects. + * + * All standard descriptors have their elements named in an identical manner to the official USB specification, + * however slightly more verbose alternate (non-standard) names are also supplied if the macro + * USE_NONSTANDARD_DESCRIPTOR_NAMES is defined in the user project makefile and passed to the compiler at + * compilation time using the -D option. + * + * The non-standard names are documented here - if USE_NONSTANDARD_DESCRIPTOR_NAMES is not defined, then all + * descriptors will contain elements named identically to the official USB specification. The alternately + * named descriptor elements are placed in the same order inside the descriptor structures as their officially + * named counterparts, thus they can be correlated easily with the official USB specification. + */ + +#ifndef __USBDESCRIPTORS_H__ +#define __USBDESCRIPTORS_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + #include "../LowLevel/USBMode.h" + #include "Events.h" + + #if defined(USB_CAN_BE_DEVICE) + #include "../LowLevel/Device.h" + #endif + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Indicates that a given descriptor does not exist in the device. This can be used inside descriptors + * for string descriptor indexes, or may be use as a return value for GetDescriptor when the specified + * descriptor does not exist. + */ + #define NO_DESCRIPTOR 0 + + /** Macro to calculate the power value for the device descriptor, from a given number of milliamps. */ + #define USB_CONFIG_POWER_MA(x) (x >> 1) + + /** Macro to calculate the Unicode length of a string with a given number of Unicode characters. + * Should be used in string descriptor's headers for giving the string descriptor's byte length. + */ + #define USB_STRING_LEN(x) (sizeof(USB_Descriptor_Header_t) + (x << 1)) + + /** Macro to encode a given four digit floating point version number (e.g. 01.23) into Binary Coded + * Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the + * standard device descriptor. + */ + #define VERSION_BCD(x) ((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | \ + ((VERSION_TENTHS(x) << 4) | VERSION_HUNDREDTHS(x))) + + /** String language ID for the English language. Should be used in USB_Descriptor_Language_t descriptors + * to indicate that the English language is supported by the device in its string descriptors. + */ + #define LANGUAGE_ID_ENG 0x0409 + + /** Can be masked with an endpoint address for a USB_Descriptor_Endpoint_t endpoint descriptor's + * EndpointAddress value to indicate to the host that the endpoint is of the IN direction (i.e, from + * device to host). + */ + #define ENDPOINT_DESCRIPTOR_DIR_IN 0x80 + + /** Can be masked with an endpoint address for a USB_Descriptor_Endpoint_t endpoint descriptor's + * EndpointAddress value to indicate to the host that the endpoint is of the OUT direction (i.e, from + * host to device). + */ + #define ENDPOINT_DESCRIPTOR_DIR_OUT 0x00 + + /** Can be masked with other configuration descriptor attributes for a USB_Descriptor_Configuration_Header_t + * descriptor's ConfigAttributes value to indicate that the specified configuration can draw its power + * from the host's VBUS line. + */ + #define USB_CONFIG_ATTR_BUSPOWERED 0b10000000 + + /** Can be masked with other configuration descriptor attributes for a USB_Descriptor_Configuration_Header_t + * descriptor's ConfigAttributes value to indicate that the specified configuration can draw its power + * from the device's own power source. + */ + #define USB_CONFIG_ATTR_SELFPOWERED 0b11000000 + + /** Can be masked with other configuration descriptor attributes for a USB_Descriptor_Configuration_Header_t + * descriptor's ConfigAttributes value to indicate that the specified configuration supports the + * remote wakeup feature of the USB standard, allowing a suspended USB device to wake up the host upon + * request. + */ + #define USB_CONFIG_ATTR_REMOTEWAKEUP 0b10100000 + + /** Can be masked with other endpoint descriptor attributes for a USB_Descriptor_Endpoint_t descriptor's + * Attributes value to indicate that the specified endpoint is not synchronized. + * + * \see The USB specification for more details on the possible Endpoint attributes. + */ + #define ENDPOINT_ATTR_NO_SYNC (0b00 << 2) + + /** Can be masked with other endpoint descriptor attributes for a USB_Descriptor_Endpoint_t descriptor's + * Attributes value to indicate that the specified endpoint is asynchronous. + * + * \see The USB specification for more details on the possible Endpoint attributes. + */ + #define ENDPOINT_ATTR_ASYNC (0b01 << 2) + + /** Can be masked with other endpoint descriptor attributes for a USB_Descriptor_Endpoint_t descriptor's + * Attributes value to indicate that the specified endpoint is adaptive. + * + * \see The USB specification for more details on the possible Endpoint attributes. + */ + #define ENDPOINT_ATTR_ADAPTIVE (0b10 << 2) + + /** Can be masked with other endpoint descriptor attributes for a USB_Descriptor_Endpoint_t descriptor's + * Attributes value to indicate that the specified endpoint is synchronized. + * + * \see The USB specification for more details on the possible Endpoint attributes. + */ + #define ENDPOINT_ATTR_SYNC (0b11 << 2) + + /** Can be masked with other endpoint descriptor attributes for a USB_Descriptor_Endpoint_t descriptor's + * Attributes value to indicate that the specified endpoint is used for data transfers. + * + * \see The USB specification for more details on the possible Endpoint usage attributes. + */ + #define ENDPOINT_USAGE_DATA (0b00 << 4) + + /** Can be masked with other endpoint descriptor attributes for a USB_Descriptor_Endpoint_t descriptor's + * Attributes value to indicate that the specified endpoint is used for feedback. + * + * \see The USB specification for more details on the possible Endpoint usage attributes. + */ + #define ENDPOINT_USAGE_FEEDBACK (0b01 << 4) + + /** Can be masked with other endpoint descriptor attributes for a USB_Descriptor_Endpoint_t descriptor's + * Attributes value to indicate that the specified endpoint is used for implicit feedback. + * + * \see The USB specification for more details on the possible Endpoint usage attributes. + */ + #define ENDPOINT_USAGE_IMPLICIT_FEEDBACK (0b10 << 4) + + /** Gives a void pointer to the specified descriptor (of any type). */ + #define DESCRIPTOR_ADDRESS(Descriptor) ((void*)&Descriptor) + + /* Events: */ + #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) + /** This module raises the Device Error event while in device mode, if the USB_GetDescriptor() + * routine is not hooked in the user application to properly return descriptors to the library. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_DeviceError); + #endif + + /* Enums: */ + /** Enum for the possible standard descriptor types, as given in each descriptor's header. */ + enum USB_DescriptorTypes_t + { + DTYPE_Device = 0x01, /**< Indicates that the descriptor is a device descriptor. */ + DTYPE_Configuration = 0x02, /**< Indicates that the descriptor is a configuration descriptor. */ + DTYPE_String = 0x03, /**< Indicates that the descriptor is a string descriptor. */ + DTYPE_Interface = 0x04, /**< Indicates that the descriptor is an interface descriptor. */ + DTYPE_Endpoint = 0x05, /**< Indicates that the descriptor is an endpoint descriptor. */ + DTYPE_DeviceQualifier = 0x06, /**< Indicates that the descriptor is a device qualifier descriptor. */ + DTYPE_Other = 0x07, /**< Indicates that the descriptor is of other type. */ + DTYPE_InterfacePower = 0x08, /**< Indicates that the descriptor is an interface power descriptor. */ + DTYPE_InterfaceAssociation = 0x0B, /**< Indicates that the descriptor is an interface association descriptor. */ + }; + + /* Type Defines: */ + /** Type define for all descriptor's header, indicating the descriptor's length and type. + * + * \note The non-standard structure element names are documented here - see the StdDescriptors.h file + * documentation for more information on the two descriptor naming schemes. If the + * USE_NONSTANDARD_DESCRIPTOR_NAMES token is not set, this structure contains elements with names + * identical to those listed in the USB standard. + */ + typedef struct + { + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + uint8_t Size; /**< Size of the descriptor, in bytes. */ + uint8_t Type; /**< Type of the descriptor, either a value in DescriptorTypes_t or a value + * given by the specific class. + */ + #else + uint8_t bLength; + uint8_t bDescriptorType; + #endif + } USB_Descriptor_Header_t; + + /** Type define for a standard device descriptor. + * + * \note The non-standard structure element names are documented here - see the StdDescriptors.h file + * documentation for more information on the two descriptor naming schemes. If the + * USE_NONSTANDARD_DESCRIPTOR_NAMES token is not set, this structure contains elements with names + * identical to those listed in the USB standard. + */ + typedef struct + { + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ + + uint16_t USBSpecification; /**< BCD of the supported USB specification. */ + uint8_t Class; /**< USB device class. */ + uint8_t SubClass; /**< USB device subclass. */ + uint8_t Protocol; /**< USB device protocol. */ + + uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */ + + uint16_t VendorID; /**< Vendor ID for the USB product. */ + uint16_t ProductID; /**< Unique product ID for the USB product. */ + uint16_t ReleaseNumber; /**< Product release (version) number. */ + + uint8_t ManufacturerStrIndex; /**< String index for the manufacturer's name. The + * host will request this string via a seperate + * control request for the string descriptor. + * + * \note If no string supplied, use NO_DESCRIPTOR. + */ + uint8_t ProductStrIndex; /**< String index for the product name/details. + * + * \see ManufacturerStrIndex structure entry. + */ + uint8_t SerialNumStrIndex; /**< String index for the product's globally unique hexadecimal + * serial number, in uppercase Unicoded ASCII. + * + * \see ManufacturerStrIndex structure entry. + */ + + uint8_t NumberOfConfigurations; /**< Total number of configurations supported by + * the device. + */ + #else + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; + #endif + } USB_Descriptor_Device_t; + + /** Type define for a standard configuration descriptor. + * + * \note The non-standard structure element names are documented here - see the StdDescriptors.h file + * documentation for more information on the two descriptor naming schemes. If the + * USE_NONSTANDARD_DESCRIPTOR_NAMES token is not set, this structure contains elements with names + * identical to those listed in the USB standard. + */ + typedef struct + { + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ + + uint16_t TotalConfigurationSize; /**< Size of the configuration descriptor header, + * and all sub descriptors inside the configuration. + */ + uint8_t TotalInterfaces; /**< Total number of interfaces in the configuration. */ + + uint8_t ConfigurationNumber; /**< Configuration index of the current configuration. */ + uint8_t ConfigurationStrIndex; /**< Index of a string descriptor describing the configuration. */ + + uint8_t ConfigAttributes; /**< Configuration attributes, comprised of a mask of zero or + * more USB_CONFIG_ATTR_* masks. + */ + + uint8_t MaxPowerConsumption; /**< Maximum power consumption of the device while in the + * current configuration, calculated by the USB_CONFIG_POWER_MA() + * macro. + */ + #else + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; + #endif + } USB_Descriptor_Configuration_Header_t; + + /** Type define for a standard interface descriptor. + * + * \note The non-standard structure element names are documented here - see the StdDescriptors.h file + * documentation for more information on the two descriptor naming schemes. If the + * USE_NONSTANDARD_DESCRIPTOR_NAMES token is not set, this structure contains elements with names + * identical to those listed in the USB standard. + */ + typedef struct + { + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ + + uint8_t InterfaceNumber; /**< Index of the interface in the current configuration. */ + uint8_t AlternateSetting; /**< Alternate setting for the interface number. The same + * interface number can have multiple alternate settings + * with different endpoint configurations, which can be + * selected by the host. + */ + uint8_t TotalEndpoints; /**< Total number of endpoints in the interface. */ + + uint8_t Class; /**< Interface class ID. */ + uint8_t SubClass; /**< Interface subclass ID. */ + uint8_t Protocol; /**< Interface protocol ID. */ + + uint8_t InterfaceStrIndex; /**< Index of the string descriptor describing the + * interface. + */ + #else + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; + #endif + } USB_Descriptor_Interface_t; + + /** Type define for a standard interface association descriptor. + * + * This descriptor has been added as a suppliment to the USB2.0 standard, in the ECN located at + * http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf. It allows compound + * devices with multiple interfaces related to the same function to have the multiple interfaces bound + * together at the point of enumeration, loading one generic driver for all the interfaces in the single + * function. Read the ECN for more information. + * + * \note The non-standard structure element names are documented here - see the StdDescriptors.h file + * documentation for more information on the two descriptor naming schemes. If the + * USE_NONSTANDARD_DESCRIPTOR_NAMES token is not set, this structure contains elements with names + * identical to those listed in the USB standard. + */ + typedef struct + { + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ + + uint8_t FirstInterfaceIndex; /**< Index of the first associated interface. */ + uint8_t TotalInterfaces; /** Total number of associated interfaces. */ + + uint8_t Class; /**< Interface class ID. */ + uint8_t SubClass; /**< Interface subclass ID. */ + uint8_t Protocol; /**< Interface protocol ID. */ + + uint8_t IADStrIndex; /**< Index of the string descriptor describing the + * interface association. + */ + #else + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bFirstInterface; + uint8_t bInterfaceCount; + uint8_t bFunctionClass; + uint8_t bFunctionSubClass; + uint8_t bFunctionProtocol; + uint8_t iFunction; + #endif + } USB_Descriptor_Interface_Association_t; + + /** Type define for a standard endpoint descriptor. + * + * \note The non-standard structure element names are documented here - see the StdDescriptors.h file + * documentation for more information on the two descriptor naming schemes. If the + * USE_NONSTANDARD_DESCRIPTOR_NAMES token is not set, this structure contains elements with names + * identical to those listed in the USB standard. + */ + typedef struct + { + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ + + uint8_t EndpointAddress; /**< Logical address of the endpoint within the device + * for the current configuration, including direction + * mask. + */ + uint8_t Attributes; /**< Endpoint attributes, comprised of a mask of the + * endpoint type (EP_TYPE_*) and attributes (ENDPOINT_ATTR_*) + * masks. + */ + uint16_t EndpointSize; /**< Size of the endpoint bank, in bytes. This indicates the + * maximum packet size that the endpoint can receive at a time. + */ + + uint8_t PollingIntervalMS; /**< Polling interval in milliseconds for the endpont + * if it is an INTERRUPT or ISOCHRONOUS type. + */ + #else + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; + #endif + } USB_Descriptor_Endpoint_t; + + /** Type define for a standard string descriptor. Unlike other standard descriptors, the length + * of the descriptor for placement in the descriptor header must be determined by the USB_STRING_LEN() + * macro rather than by the size of the descriptor structure, as the length is not fixed. + * + * This structure should also be used for string index 0, which contains the supported language IDs for + * the device as an array. + * + * \note The non-standard structure element names are documented here - see the StdDescriptors.h file + * documentation for more information on the two descriptor naming schemes. If the + * USE_NONSTANDARD_DESCRIPTOR_NAMES token is not set, this structure contains elements with names + * identical to those listed in the USB standard. + */ + typedef struct + { + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) + USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ + + int16_t UnicodeString[]; /**< String data, as unicode characters (alternatively, + * string language IDs). If normal ASCII characters are + * to be used, they must be added as an array of characters + * rather than a normal C string so that they are widened to + * Unicode size. + * + * Under GCC, strings prefixed with the "L" character (before + * the opening string quotation mark) are considered to be + * Unicode strings, and may be used instead of an explicit + * array of ASCII characters. + */ + #else + uint8_t bLength; + uint8_t bDescriptorType; + int16_t bString[]; + #endif + } USB_Descriptor_String_t; + + typedef struct + { + uint16_t Size; + void* Address; + } USB_Descriptor_Details_t; + + /* 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 except for the ATTR_WEAK attribute) so that the library can call it to retrieve descriptor + * data. + * + * \param 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 wIndex The language ID of the string to return if the wValue type indicates DTYPE_String, + * otherwise zero for standard descriptors, or as defined in a class-specific + * standards. + * \param DescriptorAddress Pointer to the descriptor in memory. This should be set by the routine to + * the location of the descriptor, found by the DESCRIPTOR_ADDRESS macro. + * + * \note By default, the library expects all descriptors to be located in flash memory via the 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 USE_SRAM_DESCRIPTORS or the + * 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 NO_DESCRIPTOR otherwise + */ + uint16_t USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress) + ATTR_WARN_UNUSED_RESULT ATTR_WEAK ATTR_NON_NULL_PTR_ARG(3); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define VERSION_TENS(x) (int)(x / 10) + #define VERSION_ONES(x) (int)(x - (10 * VERSION_TENS(x))) + #define VERSION_TENTHS(x) (int)((x - (int)x) * 10) + #define VERSION_HUNDREDTHS(x) (int)(((x - (int)x) * 100) - (10 * VERSION_TENTHS(x))) + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c new file mode 100644 index 0000000000..58faa69de4 --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c @@ -0,0 +1,252 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "../LowLevel/USBMode.h" +#include "USBInterrupt.h" + +void USB_INT_DisableAllInterrupts(void) +{ + #if defined(USB_FULL_CONTROLLER) + USBCON &= ~((1 << VBUSTE) | (1 << IDTE)); + #elif defined(USB_MODIFIED_FULL_CONTROLLER) + USBCON &= ~(1 << VBUSTE); + #endif + + #if defined(USB_CAN_BE_HOST) + UHIEN = 0; + OTGIEN = 0; + #endif + + #if defined(USB_CAN_BE_DEVICE) + UDIEN = 0; + #endif +} + +void USB_INT_ClearAllInterrupts(void) +{ + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) + USBINT = 0; + #endif + + #if defined(USB_CAN_BE_HOST) + UHINT = 0; + OTGINT = 0; + #endif + + #if defined(USB_CAN_BE_DEVICE) + UDINT = 0; + #endif +} + +ISR(USB_GEN_vect, ISR_BLOCK) +{ + #if defined(USB_CAN_BE_DEVICE) + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) + if (USB_INT_HasOccurred(USB_INT_VBUS) && USB_INT_IsEnabled(USB_INT_VBUS)) + { + USB_INT_Clear(USB_INT_VBUS); + + RAISE_EVENT(USB_VBUSChange); + + if (USB_VBUS_GetStatus()) + { + RAISE_EVENT(USB_VBUSConnect); + + if (USB_IsConnected) + RAISE_EVENT(USB_Disconnect); + + USB_ResetInterface(); + + USB_IsConnected = true; + + RAISE_EVENT(USB_Connect); + } + else + { + RAISE_EVENT(USB_Disconnect); + + USB_Detach(); + USB_CLK_Freeze(); + USB_PLL_Off(); + USB_REG_Off(); + + USB_IsConnected = false; + + RAISE_EVENT(USB_VBUSDisconnect); + + USB_INT_Clear(USB_INT_VBUS); + } + } + #endif + + if (USB_INT_HasOccurred(USB_INT_SUSPEND) && USB_INT_IsEnabled(USB_INT_SUSPEND)) + { + USB_INT_Clear(USB_INT_SUSPEND); + + USB_INT_Disable(USB_INT_SUSPEND); + USB_INT_Enable(USB_INT_WAKEUP); + + USB_CLK_Freeze(); + + if (!(USB_Options & USB_OPT_MANUAL_PLL)) + USB_PLL_Off(); + + USB_IsSuspended = true; + + RAISE_EVENT(USB_Suspend); + + #if defined(USB_LIMITED_CONTROLLER) && !defined(NO_LIMITED_CONTROLLER_CONNECT) + if (USB_IsConnected) + { + USB_IsConnected = false; + RAISE_EVENT(USB_Disconnect); + } + #endif + } + + if (USB_INT_HasOccurred(USB_INT_WAKEUP) && USB_INT_IsEnabled(USB_INT_WAKEUP)) + { + if (!(USB_Options & USB_OPT_MANUAL_PLL)) + { + USB_PLL_On(); + while (!(USB_PLL_IsReady())); + } + + USB_CLK_Unfreeze(); + + USB_INT_Clear(USB_INT_WAKEUP); + + USB_INT_Disable(USB_INT_WAKEUP); + USB_INT_Enable(USB_INT_SUSPEND); + + #if defined(USB_LIMITED_CONTROLLER) && !defined(NO_LIMITED_CONTROLLER_CONNECT) + if (!(USB_IsConnected)) + { + USB_IsConnected = true; + RAISE_EVENT(USB_Connect); + } + #endif + + USB_IsSuspended = false; + + RAISE_EVENT(USB_WakeUp); + } + + if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI)) + { + USB_INT_Clear(USB_INT_EORSTI); + + USB_ConfigurationNumber = 0; + + USB_INT_Clear(USB_INT_SUSPEND); + USB_INT_Disable(USB_INT_SUSPEND); + USB_INT_Enable(USB_INT_WAKEUP); + + Endpoint_ClearEndpoints(); + + Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, + ENDPOINT_DIR_OUT, USB_ControlEndpointSize, + ENDPOINT_BANK_SINGLE); + + RAISE_EVENT(USB_Reset); + } + #endif + + #if defined(USB_CAN_BE_HOST) + 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); + + RAISE_EVENT(USB_DeviceUnattached); + RAISE_EVENT(USB_Disconnect); + + 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(); + + RAISE_EVENT(USB_HostError, HOST_ERROR_VBusVoltageDip); + RAISE_EVENT(USB_DeviceUnattached); + + USB_HostState = HOST_STATE_Unattached; + } + + if (USB_INT_HasOccurred(USB_INT_SRPI) && USB_INT_IsEnabled(USB_INT_SRPI)) + { + USB_INT_Clear(USB_INT_SRPI); + USB_INT_Disable(USB_INT_SRPI); + + RAISE_EVENT(USB_DeviceAttached); + + USB_INT_Enable(USB_INT_DDISCI); + + USB_HostState = HOST_STATE_Attached; + } + + if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI)) + { + USB_INT_Clear(USB_INT_BCERRI); + + RAISE_EVENT(USB_DeviceEnumerationFailed, HOST_ENUMERROR_NoDeviceDetected, 0); + RAISE_EVENT(USB_DeviceUnattached); + + if (USB_IsConnected) + RAISE_EVENT(USB_Disconnect); + + 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_IsConnected) + { + if (USB_CurrentMode == USB_MODE_HOST) + RAISE_EVENT(USB_DeviceUnattached); + else + RAISE_EVENT(USB_Disconnect); + } + + RAISE_EVENT(USB_UIDChange); + + USB_ResetInterface(); + } + #endif +} diff --git a/LUFA/Drivers/USB/HighLevel/USBInterrupt.h b/LUFA/Drivers/USB/HighLevel/USBInterrupt.h new file mode 100644 index 0000000000..8438a589ed --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/USBInterrupt.h @@ -0,0 +1,224 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Main USB interrupt vector handler. This file manages the main USB interrupt vector, for handling such + * events as VBUS interrupts (on supported USB AVR models), device connections and disconnections, etc. + */ + +#ifndef __USBINTERRUPT_H__ +#define __USBINTERRUPT_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + #include "../LowLevel/LowLevel.h" + #include "../LowLevel/USBMode.h" + #include "Events.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Vector name for the common endpoint and pipe vector. This can be used to write an ISR handler + * for the endpoint and pipe events, to make certain USB functions interrupt rather than poll + * driven. + */ + #define ENDPOINT_PIPE_vect USB_COM_vect + + /** Enables the given USB interrupt vector (such as the ENDPOINT_INT_* and PIPE_INT_* vectors in + * Endpoint.h and Pipe.h). + */ + #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE + + /** Disables the given USB interrupt vector. + * + * \see USB_INT_Enable() + */ + #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE + + /** Resets the given USB interrupt flag, so that the interrupt is re-primed for the next firing. */ + #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE + + /** Returns boolean false if the given USB interrupt is disabled, or true if the interrupt is currently + * enabled. + */ + #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false) + + /** Returns boolean true if the given interrupt flag is set (i.e. the condition for the interrupt has occurred, + * but the interrupt vector is not neccesarily enabled), otherwise returns false. + */ + #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false) + + /* Throwable Events: */ + /** This module raises the USB Connected interrupt when the AVR is attached to a host while in device + * USB mode. + * + * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller. + * this means that the current connection state is derived from the bus suspension and wake up events by default, + * which is not always accurate (host may suspend the bus while still connected). If the actual connection state + * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by + * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection + * and disconnection events may be manually fired by RAISE_EVENT(), and the USB_IsConnected global changed manually. + */ + RAISES_EVENT(USB_Connect); + + /** This module raises the USB Disconnected interrupt when the AVR is removed from a host while in + * device USB mode. + * + * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller. + * this means that the current connection state is derived from the bus suspension and wake up events by default, + * which is not always accurate (host may suspend the bus while still connected). If the actual connection state + * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by + * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection + * and disconnection events may be manually fired by RAISE_EVENT(), and the USB_IsConnected global changed manually. + */ + RAISES_EVENT(USB_Disconnect); + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__) + /** This module raises the VBUS Change event when the current VBUS status (present or not present) has + * changed. + * + * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_VBUSChange); + + /** This module raises the VBUS Connect event when the VBUS line is powered. + * + * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_VBUSConnect); + + /** This module raises the VBUS Disconnect event when power is removed from the VBUS line. + * + * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_VBUSDisconnect); + #endif + + #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) + /** This module raises the Suspended event when the host suspends the USB interface of the AVR + * whilst running in device mode. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_Suspend); + + /** This module raises the Wake Up event when the host resumes the USB interface of the AVR + * whilst running in device mode. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_WakeUp); + + /** This module raises the USB Reset event when the host resets the USB interface of the AVR + * whilst running in device mode. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_Reset); + #endif + + #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) + /** This module raises the Host Error event when the VBUS line voltage dips below the minimum threshold + * while running in host mode. + * + * \note Not all USB AVR models support host mode; this event only exists on supported AVRs. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_HostError); + + /** This module raises the Device Unattached event when an attached device is removed from the AVR whilst + * running in host mode. + * + * \note Not all USB AVR models support host mode; this event only exists on supported AVRs. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_DeviceUnattached); + #endif + + #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) + /** This module raises the UID Change event when the UID line changes in value on dual-role devices. + * + * \note Not all USB AVR models support host mode and thus the UID pin; this event only exists on + * supported AVRs. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_UIDChange); + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define USB_INT_GET_EN_REG(a, b, c, d) a + #define USB_INT_GET_EN_MASK(a, b, c, d) b + #define USB_INT_GET_INT_REG(a, b, c, d) c + #define USB_INT_GET_INT_MASK(a, b, c, d) d + + #define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI) + #define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI) + #define USB_INT_WAKEUP UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI) + #define USB_INT_SUSPEND UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI) + #define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI) + #define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI) + #define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI) + #define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI) + #define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI) + #define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI) + #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI) + #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI) + #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI) + + /* Function Prototypes: */ + void USB_INT_ClearAllInterrupts(void); + void USB_INT_DisableAllInterrupts(void); + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/USBTask.c b/LUFA/Drivers/USB/HighLevel/USBTask.c new file mode 100644 index 0000000000..69670232be --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/USBTask.c @@ -0,0 +1,253 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "../LowLevel/USBMode.h" + +#define INCLUDE_FROM_USBTASK_C +#include "USBTask.h" + +volatile bool USB_IsSuspended; +volatile bool USB_IsConnected; +volatile bool USB_IsInitialized; + +#if defined(USB_CAN_BE_HOST) +volatile uint8_t USB_HostState; +#endif + +TASK(USB_USBTask) +{ + #if defined(USB_HOST_ONLY) + USB_HostTask(); + #elif defined(USB_DEVICE_ONLY) + USB_DeviceTask(); + #else + if (USB_CurrentMode == USB_MODE_DEVICE) + USB_DeviceTask(); + else if (USB_CurrentMode == USB_MODE_HOST) + USB_HostTask(); + #endif +} + +#if defined(USB_CAN_BE_DEVICE) +static void USB_DeviceTask(void) +{ + if (USB_IsConnected) + { + uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint(); + + Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); + + if (Endpoint_IsSetupReceived()) + { + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + USB_Device_ProcessControlPacket(); + } + } + + Endpoint_SelectEndpoint(PrevEndpoint); + } +} +#endif + +#if defined(USB_CAN_BE_HOST) +static void USB_HostTask(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; + } + + WaitMSRemaining--; + } + else + { + USB_HostState = PostWaitState; + } + + break; + case HOST_STATE_Attached: + WaitMSRemaining = HOST_DEVICE_SETTLE_DELAY_MS; + + USB_HostState = HOST_STATE_Attached_WaitForDeviceSettle; + break; + case HOST_STATE_Attached_WaitForDeviceSettle: + _delay_ms(1); + + if (!(WaitMSRemaining--)) + { + USB_Host_VBUS_Manual_Off(); + + USB_OTGPAD_On(); + USB_Host_VBUS_Auto_Enable(); + USB_Host_VBUS_Auto_On(); + + USB_HostState = HOST_STATE_Attached_WaitForConnect; + } + + break; + case HOST_STATE_Attached_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_IsConnected = true; + RAISE_EVENT(USB_Connect); + + USB_Host_ResumeBus(); + Pipe_ClearPipes(); + + HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Attached_DoReset); + } + + break; + case HOST_STATE_Attached_DoReset: + USB_Host_ResetDevice(); + + HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Powered); + break; + case HOST_STATE_Powered: + Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL, + PIPE_TOKEN_SETUP, PIPE_CONTROLPIPE, + 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_HostRequest = (USB_Host_Request_Header_t) + { + bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE), + bRequest: REQ_GetDescriptor, + wValue: (DTYPE_Device << 8), + wIndex: 0, + wLength: PIPE_CONTROLPIPE_DEFAULT_SIZE, + }; + + uint8_t DataBuffer[PIPE_CONTROLPIPE_DEFAULT_SIZE]; + + if ((SubErrorCode = USB_Host_SendControlRequest(DataBuffer)) != HOST_SENDCONTROL_Successful) + { + ErrorCode = HOST_ENUMERROR_ControlError; + break; + } + + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) + USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)]; + #else + USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, bMaxPacketSize0)]; + #endif + + USB_Host_ResetDevice(); + + HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Default_PostReset); + break; + case HOST_STATE_Default_PostReset: + Pipe_DisablePipe(); + Pipe_DeallocateMemory(); + Pipe_ResetPipe(PIPE_CONTROLPIPE); + + Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL, + PIPE_TOKEN_SETUP, PIPE_CONTROLPIPE, + USB_ControlPipeSize, PIPE_BANK_SINGLE); + + if (!(Pipe_IsConfigured())) + { + ErrorCode = HOST_ENUMERROR_PipeConfigError; + SubErrorCode = 0; + break; + } + + Pipe_SetInfiniteINRequests(); + + USB_HostRequest = (USB_Host_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); + + RAISE_EVENT(USB_DeviceEnumerationComplete); + USB_HostState = HOST_STATE_Addressed; + + break; + } + + if ((ErrorCode != HOST_ENUMERROR_NoError) && (USB_HostState != HOST_STATE_Unattached)) + { + RAISE_EVENT(USB_DeviceEnumerationFailed, ErrorCode, SubErrorCode); + + USB_Host_VBUS_Auto_Off(); + + RAISE_EVENT(USB_DeviceUnattached); + + if (USB_IsConnected) + RAISE_EVENT(USB_Disconnect); + + USB_ResetInterface(); + } +} +#endif diff --git a/LUFA/Drivers/USB/HighLevel/USBTask.h b/LUFA/Drivers/USB/HighLevel/USBTask.h new file mode 100644 index 0000000000..1fcc2bbb3e --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/USBTask.h @@ -0,0 +1,198 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Main library USB management task for both Host and Device mode operations. This contains the master + * USB_USBTask task which should be periodically run to service both host and device USB projects. + */ + +#ifndef __USBTASK_H__ +#define __USBTASK_H__ + + /* Includes: */ + #include + #include + #include + #include + #include + + #include "../../../Scheduler/Scheduler.h" + #include "../LowLevel/LowLevel.h" + #include "../LowLevel/HostChapter9.h" + #include "../LowLevel/USBMode.h" + #include "Events.h" + #include "StdDescriptors.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Global Variables: */ + /** Indicates if the USB interface is currently connected to a host if in device mode, or to a + * device while running in host mode. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + * + * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller. + * this means that the current connection state is derived from the bus suspension and wake up events by default, + * which is not always accurate (host may suspend the bus while still connected). If the actual connection state + * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by + * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection + * and disconnection events may be manually fired by RAISE_EVENT(), and the USB_IsConnected global changed manually. + */ + extern volatile bool USB_IsConnected; + + /** Indicates if the USB interface is currently initialized but not neccesarily connected to a host + * or device (i.e. if USB_Init() has been run). If this is false, all other library globals are invalid. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + extern volatile bool USB_IsInitialized; + + #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) + /** Indicates if the USB interface is currently suspended by the host when in device mode. When suspended, + * the device should consume minimal power, and cannot communicate to the host. If Remote Wakeup is + * supported by the device and USB_RemoteWakeupEnabled is true, suspension can be terminated by the device + * by issuing a Remote Wakup request. + * + * \note This global is only present if the user application can be a USB device. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + extern volatile bool USB_IsSuspended; + #endif + + #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) + /** Indicates the current host state machine state. When in host mode, this indicates the state + * via one of the values of the USB_Host_States_t enum values in Host.h. + * + * This value may be altered by the user application to implement the HOST_STATE_Addressed, + * HOST_STATE_Configured, HOST_STATE_Ready and HOST_STATE_Suspended states which are not implemented + * by the library. + * + * \note This global is only present if the user application can be a USB host. + */ + extern volatile uint8_t USB_HostState; + #endif + + /* Throwable Events: */ + #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) + /** This module raises the USB Connect event when a USB device has been connected whilst in host + * mode, but not yet enumerated. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_Connect); + + /** This module raises the USB Device Attached event when in host mode, and a device is attached + * to the AVR's USB interface. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_DeviceAttached); + + /** This module raises the USB Device Unattached event when in host mode, and a device is removed + * from the AVR's USB interface. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_DeviceUnattached); + + /** This module raises the USB Device Enumeration Failed event when in host mode, and an + * attached USB device has failed to successfully enumerated. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_DeviceEnumerationFailed); + + /** This module raises the USB Device Enumeration Complete event when in host mode, and an + * attached USB device has been successfully enumerated and ready to be used by the user + * application. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_DeviceEnumerationComplete); + + /** This module raises the USB Disconnect event when an attached USB device is removed from the USB + * bus. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_Disconnect); + #endif + + /* Tasks: */ + /** This is the main USB management task. The USB driver requires that this task be executed + * continuously when the USB system is active (device attached in host mode, or attached to a host + * in device mode) in order to manage USB communications. This task may be executed inside an RTOS, + * scheduler (e.g. the simple LUFA Scheduler), fast timer ISR or the main user application loop. + * + * The USB task must be serviced within 50mS in all modes, when needed. The task may be serviced + * at all times, or (for minimum CPU consumption): + * + * - In device mode, it may be disabled at startup, enabled on the firing of the USB_Connect event + * and disabled again on the firing of the USB_Disconnect event. + * + * - In host mode, it may be disabled at startup, enabled on the firing of the USB_DeviceAttached + * event and disabled again on the firing of the USB_DeviceUnattached event. + * + * \see Events.h for more information on the USB events. + */ + TASK(USB_USBTask); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Function Prototypes: */ + #if defined(INCLUDE_FROM_USBTASK_C) + #if defined(USB_CAN_BE_HOST) + static void USB_HostTask(void); + #endif + + #if defined(USB_CAN_BE_DEVICE) + static void USB_DeviceTask(void); + #endif + #endif + + /* Macros: */ + #define HOST_TASK_NONBLOCK_WAIT(duration, nextstate) {USB_HostState = HOST_STATE_WaitForDevice; WaitMSRemaining = duration; PostWaitState = nextstate; } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c new file mode 100644 index 0000000000..9ea3f417cc --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c @@ -0,0 +1,313 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "USBMode.h" +#if defined(USB_CAN_BE_DEVICE) + +#define INCLUDE_FROM_DEVCHAPTER9_C +#include "DevChapter9.h" + +uint8_t USB_ConfigurationNumber; +bool USB_RemoteWakeupEnabled; +bool USB_CurrentlySelfPowered; + +void USB_Device_ProcessControlPacket(void) +{ + uint8_t bmRequestType = Endpoint_Read_Byte(); + uint8_t bRequest = Endpoint_Read_Byte(); + bool RequestHandled = false; + + switch (bRequest) + { + case REQ_GetStatus: + if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) || + (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT))) + { + USB_Device_GetStatus(bmRequestType); + RequestHandled = true; + } + + break; +#if !defined(NO_CLEARSET_FEATURE_REQUEST) + case REQ_ClearFeature: + case REQ_SetFeature: + if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT)) + { + USB_Device_ClearSetFeature(bRequest, bmRequestType); + RequestHandled = true; + } + + break; +#endif + case REQ_SetAddress: + if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) + { + USB_Device_SetAddress(); + RequestHandled = true; + } + + break; + case REQ_GetDescriptor: + if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) || + (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE))) + { + USB_Device_GetDescriptor(); + RequestHandled = true; + } + + break; + case REQ_GetConfiguration: + if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) + { + USB_Device_GetConfiguration(); + RequestHandled = true; + } + + break; + case REQ_SetConfiguration: + if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) + { + USB_Device_SetConfiguration(); + RequestHandled = true; + } + + break; + } + + if (!(RequestHandled)) + RAISE_EVENT(USB_UnhandledControlPacket, bRequest, bmRequestType); + + if (Endpoint_IsSetupReceived()) + { + Endpoint_StallTransaction(); + Endpoint_ClearSetupReceived(); + } +} + +static void USB_Device_SetAddress(void) +{ + uint8_t wValue_LSB = Endpoint_Read_Byte(); + + Endpoint_ClearSetupReceived(); + + while (!(Endpoint_IsSetupINReady())); + + Endpoint_ClearSetupIN(); + + while (!(Endpoint_IsSetupINReady())); + + UDADDR = ((1 << ADDEN) | (wValue_LSB & 0x7F)); + + return; +} + +static void USB_Device_SetConfiguration(void) +{ + uint8_t wValue_LSB = Endpoint_Read_Byte(); + bool AlreadyConfigured = (USB_ConfigurationNumber != 0); + +#if defined(USE_SINGLE_DEVICE_CONFIGURATION) + if (wValue_LSB > 1) +#else + USB_Descriptor_Device_t* DevDescriptorPtr; + + if ((USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr) == NO_DESCRIPTOR) || + #if defined(USE_RAM_DESCRIPTORS) + (wValue_LSB > DevDescriptorPtr->NumberOfConfigurations)) + #elif defined (USE_EEPROM_DESCRIPTORS) + (wValue_LSB > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations))) + #else + (wValue_LSB > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations))) + #endif +#endif + { + return; + } + + Endpoint_ClearSetupReceived(); + + USB_ConfigurationNumber = wValue_LSB; + + Endpoint_ClearSetupIN(); + + if (!(AlreadyConfigured) && USB_ConfigurationNumber) + RAISE_EVENT(USB_DeviceEnumerationComplete); + + RAISE_EVENT(USB_ConfigurationChanged); +} + +void USB_Device_GetConfiguration(void) +{ + Endpoint_ClearSetupReceived(); + + Endpoint_Write_Byte(USB_ConfigurationNumber); + + Endpoint_ClearSetupIN(); + + while (!(Endpoint_IsSetupOUTReceived())); + Endpoint_ClearSetupOUT(); +} + +static void USB_Device_GetDescriptor(void) +{ + uint16_t wValue = Endpoint_Read_Word_LE(); + uint16_t wIndex = Endpoint_Read_Word_LE(); + uint16_t wLength = Endpoint_Read_Word_LE(); + + void* DescriptorPointer; + uint16_t DescriptorSize; + + bool SendZLP; + + if ((DescriptorSize = USB_GetDescriptor(wValue, wIndex, &DescriptorPointer)) == NO_DESCRIPTOR) + return; + + Endpoint_ClearSetupReceived(); + + if (wLength > DescriptorSize) + wLength = DescriptorSize; + + while (wLength) + { + while (!(Endpoint_IsSetupINReady())) + { + if (Endpoint_IsSetupOUTReceived()) + { + Endpoint_ClearSetupOUT(); + return; + } + } + + while (wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + { + #if defined(USE_RAM_DESCRIPTORS) + Endpoint_Write_Byte(*((uint8_t*)DescriptorPointer++)); + #elif defined (USE_EEPROM_DESCRIPTORS) + Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++)); + #else + Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++)); + #endif + + wLength--; + } + + SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearSetupIN(); + } + + if (SendZLP) + { + while (!(Endpoint_IsSetupINReady())); + Endpoint_ClearSetupIN(); + } + + while (!(Endpoint_IsSetupOUTReceived())); + Endpoint_ClearSetupOUT(); +} + +static void USB_Device_GetStatus(const uint8_t bmRequestType) +{ + uint8_t CurrentStatus = 0; + + Endpoint_Discard_Word(); + + uint8_t wIndex_LSB = Endpoint_Read_Byte(); + + switch (bmRequestType) + { + case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE): + if (USB_CurrentlySelfPowered) + CurrentStatus |= FEATURE_SELFPOWERED_ENABLED; + + if (USB_RemoteWakeupEnabled) + CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED; + + break; + case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT): + Endpoint_SelectEndpoint(wIndex_LSB); + + CurrentStatus = Endpoint_IsStalled(); + + break; + } + + Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); + Endpoint_ClearSetupReceived(); + Endpoint_Write_Word_LE(CurrentStatus); + + Endpoint_ClearSetupIN(); + + while (!(Endpoint_IsSetupOUTReceived())); + Endpoint_ClearSetupOUT(); +} + +#if !defined(NO_CLEARSET_FEATURE_REQUEST) +static void USB_Device_ClearSetFeature(const uint8_t bRequest, const uint8_t bmRequestType) +{ + uint16_t wValue = Endpoint_Read_Word_LE(); + uint16_t wIndex = Endpoint_Read_Word_LE(); + + switch (bmRequestType & CONTROL_REQTYPE_RECIPIENT) + { + case REQREC_ENDPOINT: + if (wValue == FEATURE_ENDPOINT_HALT) + { + uint8_t EndpointIndex = (wIndex & ENDPOINT_EPNUM_MASK); + + if (EndpointIndex != ENDPOINT_CONTROLEP) + { + Endpoint_SelectEndpoint(EndpointIndex); + + if (Endpoint_IsEnabled()) + { + if (bRequest == REQ_ClearFeature) + { + Endpoint_ClearStall(); + Endpoint_ResetFIFO(EndpointIndex); + Endpoint_ResetDataToggle(); + } + else + { + Endpoint_StallTransaction(); + } + } + + Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); + Endpoint_ClearSetupReceived(); + Endpoint_ClearSetupIN(); + } + } + + break; + } +} +#endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.h b/LUFA/Drivers/USB/LowLevel/DevChapter9.h new file mode 100644 index 0000000000..5e1772a536 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.h @@ -0,0 +1,135 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Module for device mode request processing. This module allows for the processing of standard control + * requests to the default control endpoint while in device mode. + * + * \see Chapter 9 of the USB 2.0 specification. + */ + +#ifndef __DEVCHAPTER9_H__ +#define __DEVCHAPTER9_H__ + + /* Includes: */ + #include + #include + #include + + #include "../HighLevel/StdDescriptors.h" + #include "../HighLevel/Events.h" + #include "LowLevel.h" + #include "StdRequestType.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Global Variables: */ + /** Indicates the currently set configuration number of the device. USB devices may have several + * different configurations which the host can select between; this indicates the currently selected + * value, or 0 if no configuration has been selected. + * + * If a device has only one single configuration, the token USE_SINGLE_DEVICE_CONFIGURATION may be + * defined in the project makefile and passed to the compiler using the -D switch. This optimize for + * a single configuration, saving a small amount of space in the resulting compiled binary. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + extern uint8_t USB_ConfigurationNumber; + + /** Indicates if the host is currently allowing the device to issue remote wakeup events. If this + * flag is cleared, the device should not issue remote wakeup events to the host. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + extern bool USB_RemoteWakeupEnabled; + + /** Indicates if the device is currently being powered by its own power supply, rather than being + * powered by the host's USB supply. This flag should remain cleared if the device does not + * support self powered mode, as indicated in the device descriptors. + */ + extern bool USB_CurrentlySelfPowered; + + /* Throwable Events: */ + /** This module raises the USB_UnhandledControlPacket event when a request to the default control + * endpoint has been received, but the library does not implement an internal handler for it. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_UnhandledControlPacket); + + /** This module raises the USB_ConfigurationChanged event when the host issues a REQ_SetConfiguration + * device request, to change the currently selected configuration number. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_ConfigurationChanged); + + /** This module raises the USB_DeviceEnumerationComplete event when the host has completed its + * enumeration of the device (i.e. when a REQ_SetConfiguration request changes the current configuration + * number from 0 to a non-zero value). + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_DeviceEnumerationComplete); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + #if defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) + #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. + #endif + + /* Function Prototypes: */ + void USB_Device_ProcessControlPacket(void); + + #if defined(INCLUDE_FROM_DEVCHAPTER9_C) + static void USB_Device_SetAddress(void); + static void USB_Device_SetConfiguration(void); + static void USB_Device_GetConfiguration(void); + static void USB_Device_GetDescriptor(void); + static void USB_Device_GetStatus(const uint8_t bmRequestType); + #if !defined(NO_CLEARSET_FEATURE_REQUEST) + static void USB_Device_ClearSetFeature(const uint8_t bRequest, const uint8_t bmRequestType); + #endif + #endif + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/Device.h b/LUFA/Drivers/USB/LowLevel/Device.h new file mode 100644 index 0000000000..187fccb4a5 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Device.h @@ -0,0 +1,126 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * USB Device mode related macros and enums. This module contains macros and enums which are used when + * the USB controller is initialized in device mode. + */ + +#ifndef __USBDEVICE_H__ +#define __USBDEVICE_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + #include "../HighLevel/StdDescriptors.h" + #include "Endpoint.h" + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__) + /** Mask for the Options parameter of the 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. + * + * \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 standard. + */ + #define USB_DEVICE_OPT_LOWSPEED (1 << 0) + #endif + + /** Mask for the Options parameter of the 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) + + /** 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 USB_RemoteWakeupEnabled flag is set, see DevChapter9.h documentation). + * + * \see StdDescriptors.h for more information on the RMWAKEUP feature and device descriptors. + */ + #define USB_Device_SendRemoteWakeup() MACROS{ UDCON |= (1 << RMWKUP); }MACROE + + /** Indicates if a Remote Wakeup request is being sent to the host. This returns true if a + * remote wakeup is currently being sent, false otherwise. + * + * This can be used in conjunction with the USB_Device_IsUSBSuspended() macro to determine if + * a sent RMWAKEUP request was accepted or rejected by the host. + * + * \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. + * + * \see StdDescriptors.h for more information on the RMWAKEUP feature and device descriptors. + */ + #define USB_Device_IsRemoteWakeupSent() ((UDCON & (1 << RMWKUP)) ? false : true) + + /** Indicates if the device is currently suspended by the host. While suspended, the device is + * to enter a low power state until resumed by the host. While suspended no USB traffic to or + * from the device can ocurr (except for Remote Wakeup requests). + * + * This macro returns true if the USB communications have been suspended by the host, false + * otherwise. + */ + #define USB_Device_IsUSBSuspended() ((UDINT & (1 << SUSPI)) ? true : false) + + /* Enums: */ + /** Enum for the ErrorCode parameter of the USB_DeviceError event. + * + * \see Events.h for more information on this event. + */ + enum USB_Device_ErrorCodes_t + { + DEVICE_ERROR_GetDescriptorNotHooked = 0, /**< Indicates that the GetDescriptor() method + * has not been hooked by the user application. + * + * \see StdDescriptors.h for more information on + * the GetDescriptor() method. + */ + }; + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define USB_Device_SetLowSpeed() MACROS{ UDCON |= (1 << LSM); }MACROE + #define USB_Device_SetHighSpeed() MACROS{ UDCON &= ~(1 << LSM); }MACROE + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c new file mode 100644 index 0000000000..273e1908a6 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c @@ -0,0 +1,387 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "USBMode.h" +#if defined(USB_CAN_BE_DEVICE) + +#define INCLUDE_FROM_ENDPOINT_C +#include "Endpoint.h" + +#if !defined(FIXED_CONTROL_ENDPOINT_SIZE) +uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; +#endif + +#if !defined(STATIC_ENDPOINT_CONFIGURATION) +bool Endpoint_ConfigureEndpoint(const uint8_t Number, const uint8_t Type, const uint8_t Direction, + const uint16_t Size, const uint8_t Banks) +{ + Endpoint_SelectEndpoint(Number); + Endpoint_EnableEndpoint(); + + UECFG1X = 0; + + UECFG0X = ((Type << EPTYPE0) | Direction); + UECFG1X = ((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size)); + + return Endpoint_IsConfigured(); +} +#else +bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData) +{ + Endpoint_SelectEndpoint(Number); + Endpoint_EnableEndpoint(); + + UECFG1X = 0; + + UECFG0X = UECFG0XData; + UECFG1X = UECFG1XData; + + return Endpoint_IsConfigured(); +} +#endif + +void Endpoint_ClearEndpoints(void) +{ + UEINT = 0; + + for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++) + { + Endpoint_SelectEndpoint(EPNum); + UEIENX = 0; + UEINTX = 0; + Endpoint_DeallocateMemory(); + Endpoint_DisableEndpoint(); + } +} + +uint8_t Endpoint_WaitUntilReady(void) +{ + uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + + USB_INT_Clear(USB_INT_SOFI); + + while (!(Endpoint_ReadWriteAllowed())) + { + if (!(USB_IsConnected)) + return ENDPOINT_READYWAIT_DeviceDisconnected; + else if (Endpoint_IsStalled()) + return ENDPOINT_READYWAIT_EndpointStalled; + + if (USB_INT_HasOccurred(USB_INT_SOFI)) + { + USB_INT_Clear(USB_INT_SOFI); + + if (!(TimeoutMSRem--)) + return ENDPOINT_READYWAIT_Timeout; + } + } + + return ENDPOINT_READYWAIT_NoError; +} + +uint8_t Endpoint_Discard_Stream(uint16_t Length +#if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t ErrorCode; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Endpoint_ReadWriteAllowed())) + { + Endpoint_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + + Endpoint_Discard_Byte(); + } + + return ENDPOINT_RWSTREAM_ERROR_NoError; +} + +uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length +#if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t* DataStream = (uint8_t*)Buffer; + uint8_t ErrorCode; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Endpoint_ReadWriteAllowed())) + { + Endpoint_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + + Endpoint_Write_Byte(*(DataStream++)); + } + + return ENDPOINT_RWSTREAM_ERROR_NoError; +} + +uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length +#if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); + uint8_t ErrorCode; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Endpoint_ReadWriteAllowed())) + { + Endpoint_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + + Endpoint_Write_Byte(*(DataStream--)); + } + + return ENDPOINT_RWSTREAM_ERROR_NoError; +} + +uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length +#if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t* DataStream = (uint8_t*)Buffer; + uint8_t ErrorCode; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Endpoint_ReadWriteAllowed())) + { + Endpoint_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + + *(DataStream++) = Endpoint_Read_Byte(); + } + + return ENDPOINT_RWSTREAM_ERROR_NoError; +} + +uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length +#if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); + uint8_t ErrorCode; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Endpoint_ReadWriteAllowed())) + { + Endpoint_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + + *(DataStream--) = Endpoint_Read_Byte(); + } + + return ENDPOINT_RWSTREAM_ERROR_NoError; +} + +uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) +{ + uint8_t* DataStream = (uint8_t*)Buffer; + bool SendZLP = true; + + while (Length && !(Endpoint_IsSetupOUTReceived())) + { + while (!(Endpoint_IsSetupINReady())); + + while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + { + Endpoint_Write_Byte(*(DataStream++)); + + Length--; + } + + SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearSetupIN(); + } + + if (Endpoint_IsSetupOUTReceived()) + return ENDPOINT_RWCSTREAM_ERROR_HostAborted; + + if (SendZLP) + { + while (!(Endpoint_IsSetupINReady())); + Endpoint_ClearSetupIN(); + } + + while (!(Endpoint_IsSetupOUTReceived())); + + return ENDPOINT_RWCSTREAM_ERROR_NoError; +} + +uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); + bool SendZLP = true; + + while (Length && !(Endpoint_IsSetupOUTReceived())) + { + while (!(Endpoint_IsSetupINReady())); + + while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + { + Endpoint_Write_Byte(*(DataStream--)); + + Length--; + } + + SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearSetupIN(); + } + + if (Endpoint_IsSetupOUTReceived()) + return ENDPOINT_RWCSTREAM_ERROR_HostAborted; + + if (SendZLP) + { + while (!(Endpoint_IsSetupINReady())); + Endpoint_ClearSetupIN(); + } + + while (!(Endpoint_IsSetupOUTReceived())); + + return ENDPOINT_RWCSTREAM_ERROR_NoError; +} + +uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) +{ + uint8_t* DataStream = (uint8_t*)Buffer; + + while (Length) + { + while (!(Endpoint_IsSetupOUTReceived())); + + while (Length && Endpoint_BytesInEndpoint()) + { + *(DataStream++) = Endpoint_Read_Byte(); + + Length--; + } + + Endpoint_ClearSetupOUT(); + } + + while (!(Endpoint_IsSetupINReady())); + + return ENDPOINT_RWCSTREAM_ERROR_NoError; +} + +uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); + + while (Length) + { + while (!(Endpoint_IsSetupOUTReceived())); + + while (Length && Endpoint_BytesInEndpoint()) + { + *(DataStream--) = Endpoint_Read_Byte(); + + Length--; + } + + Endpoint_ClearSetupOUT(); + } + + while (!(Endpoint_IsSetupINReady())); + + return ENDPOINT_RWCSTREAM_ERROR_NoError; +} + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h new file mode 100644 index 0000000000..5f3170416c --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h @@ -0,0 +1,842 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * 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/recieve functions for various datatypes. + */ + +#ifndef __ENDPOINT_H__ +#define __ENDPOINT_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + #include "../HighLevel/USBTask.h" + + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + #include "StreamCallbacks.h" + #endif + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Endpoint data direction mask for Endpoint_ConfigureEndpoint(). This indicates that the endpoint + * should be initialized in the OUT direction - i.e. data flows from host to device. + */ + #define ENDPOINT_DIR_OUT 0 + + /** Endpoint data direction mask for Endpoint_ConfigureEndpoint(). This indicates that the endpoint + * should be initialized in the IN direction - i.e. data flows from device to host. + */ + #define ENDPOINT_DIR_IN (1 << EPDIR) + + /** Mask for the bank mode selection for the Endpoint_ConfigureEndpoint() macro. This indicates + * that the endpoint should have one single bank, which requires less USB FIFO memory but results + * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's + * bank at the one time. + */ + #define ENDPOINT_BANK_SINGLE 0 + + /** Mask for the bank mode selection for the Endpoint_ConfigureEndpoint() macro. This indicates + * that the endpoint should have two banks, which requires more USB FIFO memory but results + * in faster transfers as one USB device (the AVR or the host) can access one bank while the other + * accesses the second bank. + */ + #define ENDPOINT_BANK_DOUBLE (1 << EPBK0) + + /** 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 + + /** Default size of the default control endpoint's bank, until altered by the Endpoint0Size value + * in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined. + */ + #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__)) + #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8 + #endif + + /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's + * numerical address in the device. + */ + #define ENDPOINT_EPNUM_MASK 0b111 + + /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's + * bank size in the device. + */ + #define ENDPOINT_EPSIZE_MASK 0x7FF + + /** Maximum size in bytes of a given endpoint. + * + * \param n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1) + */ + #define ENDPOINT_MAX_SIZE(n) _ENDPOINT_GET_MAXSIZE(n) + + /** Indicates if the given endpoint supports double banking. + * + * \param n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1) + */ + #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n) + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__) + /** Total number of endpoints (including the default control endpoint at address 0) which may + * be used in the device. Different USB AVR models support different amounts of endpoints, + * this value reflects the maximum number of endpoints for the currently selected AVR model. + */ + #define ENDPOINT_TOTAL_ENDPOINTS 7 + #else + #define ENDPOINT_TOTAL_ENDPOINTS 5 + #endif + + /** Interrupt definition for the endpoint SETUP interrupt (for CONTROL type endpoints). Should be + * used with the USB_INT_* macros located in USBInterrupt.h. + * + * This interrupt will fire if enabled on a CONTROL type endpoint if a new control packet is + * received from the host. + */ + #define ENDPOINT_INT_SETUP UEIENX, (1 << RXSTPE), UEINTX, (1 << RXSTPI) + + /** Interrupt definition for the endpoint IN interrupt (for INTERRUPT type endpoints). Should be + * used with the USB_INT_* macros located in USBInterrupt.h. + * + * This interrupt will fire if enabled on an INTERRUPT type endpoint if a the endpoint interrupt + * period has elapsed and the endpoint is ready for a new packet to be written to its FIFO buffer + * (if required). + */ + #define ENDPOINT_INT_IN UEIENX, (1 << TXINE) , UEINTX, (1 << TXINI) + + /** Interrupt definition for the endpoint OUT interrupt (for INTERRUPT type endpoints). Should be + * used with the USB_INT_* macros located in USBInterrupt.h. + * + * This interrupt will fire if enabled on an INTERRUPT type endpoint if a the endpoint interrupt + * period has elapsed and the endpoint is ready for a packet from the host to be read from its + * FIFO buffer (if received). + */ + #define ENDPOINT_INT_OUT UEIENX, (1 << RXOUTE), UEINTX, (1 << RXOUTI) + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__) + /** Indicates the number of bytes currently stored in the current endpoint's selected bank. */ + #define Endpoint_BytesInEndpoint() UEBCX + #else + #define Endpoint_BytesInEndpoint() UEBCLX + #endif + + /** Returns the endpoint address of the currently selected endpoint. This is typically used to save + * the currently selected endpoint number so that it can be restored after another endpoint has + * been manipulated. + */ + #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK) + + /** Selects the given endpoint number. If the address from the device descriptors is used, the + * value should be masked with the ENDPOINT_EPNUM_MASK constant to extract only the endpoint + * number (and discarding the endpoint direction bit). + * + * Any endpoint operations which do not require the endpoint number to be indicated will operate on + * the currently selected endpoint. + */ + #define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = epnum; }MACROE + + /** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's + * In and Out pointers to the bank's contents. + */ + #define Endpoint_ResetFIFO(epnum) MACROS{ UERST = (1 << epnum); UERST = 0; }MACROE + + /** Enables the currently selected endpoint so that data can be sent and received through it to + * and from a host. + * + * \note Endpoints must first be configured properly rather than just being enabled via the + * Endpoint_ConfigureEndpoint() macro, which calls Endpoint_EnableEndpoint() automatically. + */ + #define Endpoint_EnableEndpoint() MACROS{ UECONX |= (1 << EPEN); }MACROE + + /** Disables the currently selected endpoint so that data cannot be sent and received through it + * to and from a host. + */ + #define Endpoint_DisableEndpoint() MACROS{ UECONX &= ~(1 << EPEN); }MACROE + + /** Returns true if the currently selected endpoint is enabled, false otherwise. */ + #define Endpoint_IsEnabled() ((UECONX & (1 << EPEN)) ? true : false) + + /** Returns true if the currently selected endpoint may be read from (if data is waiting in the endpoint + * bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an + * IN direction). This function will return false if an error has occured in the endpoint, or if + * the endpoint is an OUT direction and no packet has been received, or if the endpoint is an IN + * direction and the endpoint bank is full. + */ + #define Endpoint_ReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false) + + /** Returns true if the currently selected endpoint is configured, false otherwise. */ + #define Endpoint_IsConfigured() ((UESTA0X & (1 << CFGOK)) ? true : false) + + /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their + * interrupt duration has elapsed. Which endpoints have interrupted can be determined by + * masking the return value against (1 << {Endpoint Number}). + */ + #define Endpoint_GetEndpointInterrupts() UEINT + + /** Clears the endpoint interrupt flag. This clears the specified endpoint number's interrupt + * mask in the endpoint interrupt flag register. + */ + #define Endpoint_ClearEndpointInterrupt(n) MACROS{ UEINT &= ~(1 << n); }MACROE + + /** Returns true if the specified endpoint number has interrupted (valid only for INTERRUPT type + * endpoints), false otherwise. + */ + #define Endpoint_HasEndpointInterrupted(n) ((UEINT & (1 << n)) ? true : false) + + /** Clears the currently selected endpoint bank, and switches to the alternate bank if the currently + * selected endpoint is dual-banked. When cleared, this either frees the bank up for the next packet + * from the host (if the endpoint is of the OUT direction) or sends the packet contents to the host + * (if the endpoint is of the IN direction). + */ + #define Endpoint_ClearCurrentBank() MACROS{ UEINTX &= ~(1 << FIFOCON); }MACROE + + /** Returns true if the current CONTROL type endpoint is ready for an IN packet, false otherwise. */ + #define Endpoint_IsSetupINReady() ((UEINTX & (1 << TXINI)) ? true : false) + + /** Returns true if the current CONTROL type endpoint is ready for an OUT packet, false otherwise. */ + #define Endpoint_IsSetupOUTReceived() ((UEINTX & (1 << RXOUTI)) ? true : false) + + /** Returns true if the current CONTROL type endpoint is ready for a SETUP packet, false otherwise. */ + #define Endpoint_IsSetupReceived() ((UEINTX & (1 << RXSTPI)) ? true : false) + + /** Clears a received SETUP packet on the currently selected CONTROL type endpoint. */ + #define Endpoint_ClearSetupReceived() MACROS{ UEINTX &= ~(1 << RXSTPI); }MACROE + + /** Sends an IN packet to the host on the currently selected CONTROL type endpoint. */ + #define Endpoint_ClearSetupIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE + + /** Acknowedges an OUT packet to the host on the currently selected CONTROL type endpoint, freeing + * up the endpoint for the next packet. + */ + #define Endpoint_ClearSetupOUT() MACROS{ UEINTX &= ~(1 << RXOUTI); }MACROE + + /** Stalls the current endpoint, indicating to the host that a logical problem occured with the + * indicated endpoint and that the current transfer sequence should be aborted. This provides a + * way for devices to indicate invalid commands to the host so that the current transfer can be + * aborted and the host can begin its own recovery seqeuence. + * + * The currently selected endpoint remains stalled until either the Endpoint_ClearStall() macro + * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected + * endpoint. + */ + #define Endpoint_StallTransaction() MACROS{ UECONX |= (1 << STALLRQ); }MACROE + + /** Clears the stall on the currently selected endpoint. */ + #define Endpoint_ClearStall() MACROS{ UECONX |= (1 << STALLRQC); }MACROE + + /** Returns true if the currently selected endpoint is stalled, false othewise. */ + #define Endpoint_IsStalled() ((UECONX & (1 << STALLRQ)) ? true : false) + + /** Resets the data toggle of the currently selected endpoint. */ + #define Endpoint_ResetDataToggle() MACROS{ UECONX |= (1 << RSTDT); }MACROE + + /* Enums: */ + /** Enum for the possible error return codes of the Endpoint_WaitUntilReady function */ + enum Endpoint_WaitUntilReady_ErrorCodes_t + { + ENDPOINT_READYWAIT_NoError = 0, /**< Endpoint is ready for next packet, no error. */ + ENDPOINT_READYWAIT_EndpointStalled = 1, /**< The endpoint was stalled during the stream + * transfer by the host or device. + */ + ENDPOINT_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while + * waiting for the endpoint to become ready. + */ + ENDPOINT_READYWAIT_Timeout = 3, /**< The host failed to accept or send the next packet + * within the software timeout period set by the + * USB_STREAM_TIMEOUT_MS macro. + */ + }; + + /** Enum for the possible error return codes of the Endpoint_*_Stream_* functions. */ + enum Endpoint_Stream_RW_ErrorCodes_t + { + ENDPOINT_RWSTREAM_ERROR_NoError = 0, /**< Command completed successfully, no error. */ + ENDPOINT_RWSTREAM_ERROR_EndpointStalled = 1, /**< The endpoint was stalled during the stream + * transfer by the host or device. + */ + ENDPOINT_RWSTREAM_ERROR_DeviceDisconnected = 1, /**< Device was disconnected from the host during + * the transfer. + */ + ENDPOINT_RWSTREAM_ERROR_Timeout = 2, /**< The host failed to accept or send the next packet + * within the software timeout period set by the + * USB_STREAM_TIMEOUT_MS macro. + */ + ENDPOINT_RWSTREAM_ERROR_CallbackAborted = 3, /**< Indicates that the stream's callback function + * aborted the transfer early. + */ + }; + + /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions. */ + enum Endpoint_ControlStream_RW_ErrorCodes_t + { + ENDPOINT_RWCSTREAM_ERROR_NoError = 0, /**< Command completed successfully, no error. */ + ENDPOINT_RWCSTREAM_ERROR_HostAborted = 1, /**< The aborted the transfer prematurely. */ + }; + + /* Inline Functions: */ + /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints. */ + static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Endpoint_Read_Byte(void) + { + return UEDATX; + } + + /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints. */ + static inline void Endpoint_Write_Byte(const uint8_t Byte) + { + UEDATX = Byte; + } + + /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints. */ + static inline void Endpoint_Discard_Byte(void) + { + uint8_t Dummy; + + Dummy = UEDATX; + } + + /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT + * direction endpoints. + */ + static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT; + static inline uint16_t Endpoint_Read_Word_LE(void) + { + uint16_t Data; + + Data = UEDATX; + Data |= (((uint16_t)UEDATX) << 8); + + return Data; + } + + /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT + * direction endpoints. + */ + static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT; + static inline uint16_t Endpoint_Read_Word_BE(void) + { + uint16_t Data; + + Data = (((uint16_t)UEDATX) << 8); + Data |= UEDATX; + + return Data; + } + + /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN + * direction endpoints. + */ + static inline void Endpoint_Write_Word_LE(const uint16_t Word) + { + UEDATX = (Word & 0xFF); + UEDATX = (Word >> 8); + } + + /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN + * direction endpoints. + */ + static inline void Endpoint_Write_Word_BE(const uint16_t Word) + { + UEDATX = (Word >> 8); + UEDATX = (Word & 0xFF); + } + + /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints. */ + static inline void Endpoint_Discard_Word(void) + { + uint8_t Dummy; + + Dummy = UEDATX; + Dummy = UEDATX; + } + + /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT + * direction endpoints. + */ + static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT; + static inline uint32_t Endpoint_Read_DWord_LE(void) + { + union + { + uint32_t DWord; + uint8_t Bytes[4]; + } Data; + + Data.Bytes[0] = UEDATX; + Data.Bytes[1] = UEDATX; + Data.Bytes[2] = UEDATX; + Data.Bytes[3] = UEDATX; + + return Data.DWord; + } + + /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT + * direction endpoints. + */ + static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT; + static inline uint32_t Endpoint_Read_DWord_BE(void) + { + union + { + uint32_t DWord; + uint8_t Bytes[4]; + } Data; + + Data.Bytes[3] = UEDATX; + Data.Bytes[2] = UEDATX; + Data.Bytes[1] = UEDATX; + Data.Bytes[0] = UEDATX; + + return Data.DWord; + } + + /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN + * direction endpoints. + */ + static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) + { + Endpoint_Write_Word_LE(DWord); + Endpoint_Write_Word_LE(DWord >> 16); + } + + /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN + * direction endpoints. + */ + static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) + { + Endpoint_Write_Word_BE(DWord >> 16); + Endpoint_Write_Word_BE(DWord); + } + + /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints. */ + static inline void Endpoint_Discard_DWord(void) + { + uint8_t Dummy; + + Dummy = UEDATX; + Dummy = UEDATX; + Dummy = UEDATX; + Dummy = UEDATX; + } + + /* External Variables: */ + /** Global indicating the maximum packet size of the default control endpoint located at address + * 0 in the device. This value is set to the value indicated in the device descriptor in the user + * project once the USB interface is initialized into device mode. + * + * If space is an issue, it is possible to fix this to a static value by defining the control + * endpoint size in the FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile + * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically + * read from the descriptors at runtime and instead fixed to the given value. When used, it is + * important that the descriptor control endpoint size value matches the size given as the + * FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the FIXED_CONTROL_ENDPOINT_SIZE token + * be used in the descriptors to ensure this. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__)) + extern uint8_t USB_ControlEndpointSize; + #else + #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE + #endif + + /* Function Prototypes: */ + /** Configures the specified endpoint number with the given endpoint type, direction, bank size + * and banking mode. Endpoints should be allocated in ascending order by their address in the + * device (i.e. endpoint 1 should be configured before endpoint 2 and so on). + * + * The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction + * may be either ENDPOINT_DIR_OUT or ENDPOINT_DIR_IN. + * + * The bank size must indicate the maximum packet size that the endpoint can handle. Different + * endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's + * datasheet to determine the maximum bank size for each endpoint. + * + * The banking mode may be either ENDPOINT_BANK_SINGLE or ENDPOINT_BANK_DOUBLE. + * + * The success of this routine can be determined via the Endpoint_IsConfigured() macro. + * + * By default, the routine is entirely dynamic, and will accept both constant and variable inputs. + * If dynamic configuration is unused, a small space savings can be made by defining the + * STATIC_ENDPOINT_CONFIGURATION macro via the -D switch to the compiler, to optimize for constant + * input values. + * + * \note This routine will select the specified endpoint, and the endpoint will remain selected + * once the routine completes regardless of if the endpoint configuration succeeds. + * + * \return Boolean true if the configuration succeeded, false otherwise + */ + bool Endpoint_ConfigureEndpoint(const uint8_t Number, const uint8_t Type, const uint8_t Direction, + const uint16_t Size, const uint8_t Banks); + + /** Spinloops until the currently selected non-control endpoint is ready for the next packet of data + * to be read or written to it. + * + * \note This routine should not be called on CONTROL type endpoints. + * + * \return A value from the Endpoint_WaitUntilReady_ErrorCodes_t enum. + */ + uint8_t Endpoint_WaitUntilReady(void); + + /** Reads and discards the given number of bytes from the endpoint from the given buffer, + * discarding fully read packets from the host as needed. The last packet is not automatically + * discarded once the remaining bytes has been read; the user is responsible for manually + * discarding the last packet from the host via the Endpoint_ClearCurrentBank() macro. Between + * each USB packet, the given stream callback function is executed repeatedly until the next + * packet is ready, allowing for early aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param Length Number of bytes to send via the currently selected endpoint. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Discard_Stream(uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ); + + /** Writes the given number of bytes to the endpoint from the given buffer in little endian, + * sending full packets to the host as needed. The last packet filled is not automatically sent; + * the user is responsible for manually sending the last written packet to the host via the + * Endpoint_ClearCurrentBank() macro. Between each USB packet, the given stream callback function + * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early + * aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param Buffer Pointer to the source data buffer to read from. + * \param Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ) ATTR_NON_NULL_PTR_ARG(1); + + /** Writes the given number of bytes to the endpoint from the given buffer in big endian, + * sending full packets to the host as needed. The last packet filled is not automatically sent; + * the user is responsible for manually sending the last written packet to the host via the + * Endpoint_ClearCurrentBank() macro. Between each USB packet, the given stream callback function + * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early + * aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param Buffer Pointer to the source data buffer to read from. + * \param Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads the given number of bytes from the endpoint from the given buffer in little endian, + * discarding fully read packets from the host as needed. The last packet is not automatically + * discarded once the remaining bytes has been read; the user is responsible for manually + * discarding the last packet from the host via the Endpoint_ClearCurrentBank() macro. Between + * each USB packet, the given stream callback function is executed repeatedly until the endpoint + * is ready to accept the next packet, allowing for early aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param Buffer Pointer to the destination data buffer to write to. + * \param Length Number of bytes to send via the currently selected endpoint. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads the given number of bytes from the endpoint from the given buffer in big endian, + * discarding fully read packets from the host as needed. The last packet is not automatically + * discarded once the remaining bytes has been read; the user is responsible for manually + * discarding the last packet from the host via the Endpoint_ClearCurrentBank() macro. Between + * each USB packet, the given stream callback function is executed repeatedly until the endpoint + * is ready to accept the next packet, allowing for early aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param Buffer Pointer to the destination data buffer to write to. + * \param Length Number of bytes to send via the currently selected endpoint. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ) ATTR_NON_NULL_PTR_ARG(1); + + /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian, + * sending full packets to the host as needed. The host OUT acknowedgement is not automatically cleared + * in both failure and success states; the user is responsible for manually clearing the setup OUT to + * finalize the transfer via the Endpoint_ClearSetupOUT() macro. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \param Buffer Pointer to the source data buffer to read from. + * \param Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian, + * sending full packets to the host as needed. The host OUT acknowedgement is not automatically cleared + * in both failure and success states; the user is responsible for manually clearing the setup OUT to + * finalize the transfer via the Endpoint_ClearSetupOUT() macro. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \param Buffer Pointer to the source data buffer to read from. + * \param Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian, + * discarding fully read packets from the host as needed. The device IN acknowedgement is not + * automatically sent after success or failure states; the user is responsible for manually sending the + * setup IN to finalize the transfer via the Endpoint_ClearSetupIN() macro. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \param Buffer Pointer to the destination data buffer to write to. + * \param Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian, + * discarding fully read packets from the host as needed. The device IN acknowedgement is not + * automatically sent after success or failure states; the user is responsible for manually sending the + * setup IN to finalize the transfer via the Endpoint_ClearSetupIN() macro. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \param Buffer Pointer to the destination data buffer to write to. + * \param Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /* Function Aliases: */ + /** Alias for Endpoint_Discard_Byte(). + */ + #define Endpoint_Ignore_Byte() Endpoint_Discard_Byte() + + /** Alias for Endpoint_Discard_Word(). + */ + #define Endpoint_Ignore_Word() Endpoint_Discard_Word() + + /** Alias for Endpoint_Discard_DWord(). + */ + #define Endpoint_Ignore_DWord() Endpoint_Discard_DWord() + + /** Alias for Endpoint_Read_Word_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Endpoint_Read_Word() Endpoint_Read_Word_LE() + + /** Alias for Endpoint_Write_Word_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Endpoint_Write_Word(Word) Endpoint_Write_Word_LE(Word) + + /** Alias for Endpoint_Read_DWord_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Endpoint_Read_DWord() Endpoint_Read_DWord_LE() + + /** Alias for Endpoint_Write_DWord_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Endpoint_Write_DWord(DWord) Endpoint_Write_DWord_LE(DWord) + + /** Alias for Endpoint_Read_Stream_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #if !defined(NO_STREAM_CALLBACKS) + #define Endpoint_Read_Stream(Buffer, Length, Callback) Endpoint_Read_Stream_LE(Buffer, Length, Callback) + #else + #define Endpoint_Read_Stream(Buffer, Length) Endpoint_Read_Stream_LE(Buffer, Length) + #endif + + /** Alias for Endpoint_Write_Stream_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #if !defined(NO_STREAM_CALLBACKS) + #define Endpoint_Write_Stream(Buffer, Length, Callback) Endpoint_Write_Stream_LE(Buffer, Length, Callback) + #else + #define Endpoint_Write_Stream(Buffer, Length) Endpoint_Write_Stream_LE(Buffer, Length) + #endif + + /** Alias for Endpoint_Read_Control_Stream_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Endpoint_Read_Control_Stream(Data, Length) Endpoint_Read_Control_Stream_LE(Data, Length) + + /** Alias for Endpoint_Write_Control_Stream_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Endpoint_Write_Control_Stream(Data, Length) Endpoint_Write_Control_Stream_LE(Data, Length) + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define Endpoint_AllocateMemory() MACROS{ UECFG1X |= (1 << ALLOC); }MACROE + #define Endpoint_DeallocateMemory() MACROS{ UECFG1X &= ~(1 << ALLOC); }MACROE + + #define _ENDPOINT_GET_MAXSIZE(n) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## n) + #define _ENDPOINT_GET_MAXSIZE2(details) _ENDPOINT_GET_MAXSIZE3(details) + #define _ENDPOINT_GET_MAXSIZE3(maxsize, db) maxsize + + #define _ENDPOINT_GET_DOUBLEBANK(n) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## n) + #define _ENDPOINT_GET_DOUBLEBANK2(details) _ENDPOINT_GET_DOUBLEBANK3(details) + #define _ENDPOINT_GET_DOUBLEBANK3(maxsize, db) db + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) + #define ENDPOINT_DETAILS_EP0 64, true + #define ENDPOINT_DETAILS_EP1 256, true + #define ENDPOINT_DETAILS_EP2 64, true + #define ENDPOINT_DETAILS_EP3 64, true + #define ENDPOINT_DETAILS_EP4 64, true + #define ENDPOINT_DETAILS_EP5 64, true + #define ENDPOINT_DETAILS_EP6 64, true + #else + #define ENDPOINT_DETAILS_EP0 64, true + #define ENDPOINT_DETAILS_EP1 64, false + #define ENDPOINT_DETAILS_EP2 64, false + #define ENDPOINT_DETAILS_EP3 64, true + #define ENDPOINT_DETAILS_EP4 64, true + #endif + + #if defined(STATIC_ENDPOINT_CONFIGURATION) + #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \ + Endpoint_ConfigureEndpointStatic(Number, \ + ((Type << EPTYPE0) | Direction), \ + ((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size))); + #endif + + /* Function Prototypes: */ + void Endpoint_ClearEndpoints(void); + bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData); + + /* Inline Functions: */ + static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYSINLINE; + static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) + { + if (Bytes <= 8) + return (0 << EPSIZE0); + else if (Bytes <= 16) + return (1 << EPSIZE0); + else if (Bytes <= 32) + return (2 << EPSIZE0); + #if defined(USB_LIMITED_CONTROLLER) + else + return (3 << EPSIZE0); + #else + else if (Bytes <= 64) + return (3 << EPSIZE0); + else if (Bytes <= 128) + return (4 << EPSIZE0); + else + return (5 << EPSIZE0); + #endif + }; + + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c new file mode 100644 index 0000000000..7acbffe717 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Host.c @@ -0,0 +1,115 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "USBMode.h" +#if defined(USB_CAN_BE_HOST) + +#include "Host.h" + +uint8_t USB_Host_WaitMS(uint8_t MS) +{ + bool BusSuspended = USB_Host_IsBusSuspended(); + uint8_t ErrorCode = HOST_WAITERROR_Successful; + + 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_IsConnected == false) || (USB_CurrentMode == USB_MODE_DEVICE)) + { + 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(); + + return ErrorCode; +} + +void USB_Host_ResetDevice(void) +{ + bool BusSuspended = USB_Host_IsBusSuspended(); + + USB_INT_Disable(USB_INT_DDISCI); + + USB_Host_ResetBus(); + while (!(USB_Host_IsResetBusDone())); + + USB_INT_Clear(USB_INT_HSOFI); + USB_Host_ResumeBus(); + + for (uint8_t MSRem = 10; MSRem != 0; MSRem--) + { + /* Workaround for powerless-pullup devices. After a USB bus reset, + all disconnection interrupts are supressed 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_DDISCI); + break; + } + + _delay_ms(1); + } + + if (BusSuspended) + USB_Host_SuspendBus(); + + USB_INT_Enable(USB_INT_DDISCI); +} +#endif diff --git a/LUFA/Drivers/USB/LowLevel/Host.h b/LUFA/Drivers/USB/LowLevel/Host.h new file mode 100644 index 0000000000..5cc215454d --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Host.h @@ -0,0 +1,245 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * 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 + #include + #include + + #include "../../../Common/Common.h" + #include "../HighLevel/USBInterrupt.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #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 + * 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. + * + * This value may be overridden in the user project makefile as the value of the + * HOST_DEVICE_SETTLE_DELAY_MS token, and passed to the compiler using the -D switch. + */ + #define HOST_DEVICE_SETTLE_DELAY_MS 1500 + #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. + */ + #define USB_Host_ResetBus() MACROS{ UHCON |= (1 << RESET); }MACROE + + /** Determines if a previously issued bus reset (via the USB_Host_ResetBus() macro) has + * completed. This macro returns true if no bus reset is currently being sent, false + * otherwise. + */ + #define USB_Host_IsResetBusDone() ((UHCON & (1 << RESET)) ? false : true) + + /** 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. + */ + #define USB_Host_ResumeBus() MACROS{ UHCON |= (1 << SOFEN); }MACROE + + /** Suspends the USB bus, preventing any communications from occuring 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. + */ + #define USB_Host_SuspendBus() MACROS{ UHCON &= ~(1 << SOFEN); }MACROE + + /** Returns true if the USB bus has been suspended via the use of the 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. + */ + #define USB_Host_IsBusSuspended() ((UHCON & (1 << SOFEN)) ? false : true) + + /** Returns true 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). + */ + #define USB_Host_IsDeviceFullSpeed() ((USBSTA & (1 << SPEED)) ? true : false) + + /** Returns true 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. + */ + #define USB_Host_IsRemoteWakeupSent() ((UHINT & (1 << RXRSMI)) ? true : false) + + /** Clears the flag indicating that a Remote Wakeup request has been issued by an attached + * device. + */ + #define USB_Host_ClearRemoteWakeupSent() MACROS{ UHINT &= ~(1 << RXRSMI); }MACROE + + /** 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. + */ + #define USB_Host_ResumeFromWakeupRequest() MACROS{ UHCON |= (1 << RESUME); }MACROE + + /** Returns true if no resume from Remote Wakeup request is currently being sent to an attached + * device, false otherwise. + */ + #define USB_Host_IsResumeFromWakeupRequestSent() ((UHCON & (1 << RESUME)) ? false : true) + + /* Enums: */ + /** Enum for the various states of the USB Host state machine. Only some states are + * implemented in the LUFA library - other states are left to the user to implement. + * + * For information on each state, refer to the USB 2.0 specification. Some states have + * + * \see USBTask.h for information on the global variable USB_HostState, which stores the + * current host state machine state. + */ + enum USB_Host_States_t + { + HOST_STATE_WaitForDevice = 0, /**< Internally implemented by the library. */ + HOST_STATE_Unattached = 1, /**< Internally implemented by the library. */ + HOST_STATE_Attached = 2, /**< Internally implemented by the library. */ + HOST_STATE_Attached_WaitForDeviceSettle = 3, /**< Internally implemented by the library. */ + HOST_STATE_Attached_WaitForConnect = 4, /**< Internally implemented by the library. */ + HOST_STATE_Attached_DoReset = 5, /**< Internally implemented by the library. */ + HOST_STATE_Powered = 6, /**< Internally implemented by the library. */ + HOST_STATE_Default = 7, /**< Internally implemented by the library. */ + HOST_STATE_Default_PostReset = 8, /**< Internally implemented by the library. */ + HOST_STATE_Default_PostAddressSet = 9, /**< Internally implemented by the library. */ + HOST_STATE_Addressed = 10, /**< May be implemented by the user project. */ + HOST_STATE_Configured = 11, /**< May be implemented by the user project. */ + HOST_STATE_Ready = 12, /**< May be implemented by the user project. */ + HOST_STATE_Suspended = 13, /**< May be implemented by the user project. */ + }; + + /** Enum for the error codes for the USB_HostError event. + * + * \see Events.h 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 USB_DeviceEnumerationFailed event. + * + * \see Events.h 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 USB_DeviceEnumerationFailed + * event. + */ + HOST_ENUMERROR_WaitStage = 1, /**< One of the delays between enumeration steps failed + * to complete successfuly, 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 successfuly. + */ + HOST_ENUMERROR_PipeConfigError = 4, /**< The default control pipe (address 0) failed to + * configure correctly. + */ + }; + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define USB_Host_HostMode_On() MACROS{ USBCON |= (1 << HOST); }MACROE + #define USB_Host_HostMode_Off() MACROS{ USBCON &= ~(1 << HOST); }MACROE + + #define USB_Host_VBUS_Auto_Enable() MACROS{ OTGCON &= ~(1 << VBUSHWC); UHWCON |= (1 << UVCONE); }MACROE + #define USB_Host_VBUS_Manual_Enable() MACROS{ OTGCON |= (1 << VBUSHWC); UHWCON &= ~(1 << UVCONE); DDRE |= (1 << 7); }MACROE + + #define USB_Host_VBUS_Auto_On() MACROS{ OTGCON |= (1 << VBUSREQ); }MACROE + #define USB_Host_VBUS_Manual_On() MACROS{ PORTE |= (1 << 7); }MACROE + + #define USB_Host_VBUS_Auto_Off() MACROS{ OTGCON |= (1 << VBUSRQC); }MACROE + #define USB_Host_VBUS_Manual_Off() MACROS{ PORTE &= ~(1 << 7); }MACROE + + #define USB_Host_SetDeviceAddress(addr) MACROS{ UHADDR = (addr & 0b01111111); }MACROE + + /* Enums: */ + enum USB_Host_WaitMSErrorCodes_t + { + HOST_WAITERROR_Successful = 0, + HOST_WAITERROR_DeviceDisconnect = 1, + HOST_WAITERROR_PipeError = 2, + HOST_WAITERROR_SetupStalled = 3, + }; + + /* Function Prototypes: */ + uint8_t USB_Host_WaitMS(uint8_t MS); + void USB_Host_ResetDevice(void); + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/HostChapter9.c b/LUFA/Drivers/USB/LowLevel/HostChapter9.c new file mode 100644 index 0000000000..fe168b7249 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/HostChapter9.c @@ -0,0 +1,178 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "USBMode.h" +#if defined(USB_CAN_BE_HOST) + +#define INCLUDE_FROM_HOSTCHAPTER9_C +#include "HostChapter9.h" + +USB_Host_Request_Header_t USB_HostRequest; + +uint8_t USB_Host_SendControlRequest(void* BufferPtr) +{ + uint8_t* HeaderStream = (uint8_t*)&USB_HostRequest; + uint8_t* DataStream = (uint8_t*)BufferPtr; + bool BusSuspended = USB_Host_IsBusSuspended(); + uint8_t ReturnStatus = HOST_SENDCONTROL_Successful; + uint16_t DataLen = USB_HostRequest.wLength; + + USB_Host_ResumeBus(); + + if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) + return ReturnStatus; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + Pipe_SetToken(PIPE_TOKEN_SETUP); + Pipe_ClearErrorFlags(); + Pipe_ClearSetupSent(); + + Pipe_Unfreeze(); + + for (uint8_t HeaderByte = 0; HeaderByte < sizeof(USB_Host_Request_Header_t); HeaderByte++) + Pipe_Write_Byte(*(HeaderStream++)); + + Pipe_ClearSetupOUT(); + + if ((ReturnStatus = USB_Host_Wait_For_Setup_IOS(USB_HOST_WAITFOR_SetupSent))) + goto End_Of_Control_Send; + + Pipe_ClearSetupSent(); + Pipe_Freeze(); + + if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) + goto End_Of_Control_Send; + + if ((USB_HostRequest.bmRequestType & CONTROL_REQTYPE_DIRECTION) == REQDIR_DEVICETOHOST) + { + Pipe_SetToken(PIPE_TOKEN_IN); + + if (DataStream != NULL) + { + while (DataLen) + { + Pipe_Unfreeze(); + + if ((ReturnStatus = USB_Host_Wait_For_Setup_IOS(USB_HOST_WAITFOR_InReceived))) + goto End_Of_Control_Send; + + if (!(Pipe_BytesInPipe())) + DataLen = 0; + + while (Pipe_BytesInPipe() && DataLen) + { + *(DataStream++) = Pipe_Read_Byte(); + DataLen--; + } + + Pipe_Freeze(); + Pipe_ClearSetupIN(); + } + } + + Pipe_SetToken(PIPE_TOKEN_OUT); + Pipe_Unfreeze(); + + if ((ReturnStatus = USB_Host_Wait_For_Setup_IOS(USB_HOST_WAITFOR_OutReady))) + goto End_Of_Control_Send; + + Pipe_ClearSetupOUT(); + + if ((ReturnStatus = USB_Host_Wait_For_Setup_IOS(USB_HOST_WAITFOR_OutReady))) + goto End_Of_Control_Send; + } + else + { + if (DataStream != NULL) + { + Pipe_SetToken(PIPE_TOKEN_OUT); + Pipe_Unfreeze(); + + while (DataLen) + { + if ((ReturnStatus = USB_Host_Wait_For_Setup_IOS(USB_HOST_WAITFOR_OutReady))) + goto End_Of_Control_Send; + + while (DataLen && (Pipe_BytesInPipe() < USB_ControlPipeSize)) + { + Pipe_Write_Byte(*(DataStream++)); + DataLen--; + } + + Pipe_ClearSetupOUT(); + } + + if ((ReturnStatus = USB_Host_Wait_For_Setup_IOS(USB_HOST_WAITFOR_OutReady))) + goto End_Of_Control_Send; + + Pipe_Freeze(); + } + + Pipe_SetToken(PIPE_TOKEN_IN); + Pipe_Unfreeze(); + + if ((ReturnStatus = USB_Host_Wait_For_Setup_IOS(USB_HOST_WAITFOR_InReceived))) + goto End_Of_Control_Send; + + Pipe_ClearSetupIN(); + } + +End_Of_Control_Send: + Pipe_Freeze(); + + if (BusSuspended) + USB_Host_SuspendBus(); + + Pipe_ResetPipe(PIPE_CONTROLPIPE); + + return ReturnStatus; +} + +static uint8_t USB_Host_Wait_For_Setup_IOS(const uint8_t WaitType) +{ + uint16_t TimeoutCounter = USB_HOST_TIMEOUT_MS; + + while (!(((WaitType == USB_HOST_WAITFOR_SetupSent) && Pipe_IsSetupSent()) || + ((WaitType == USB_HOST_WAITFOR_InReceived) && Pipe_IsSetupINReceived()) || + ((WaitType == USB_HOST_WAITFOR_OutReady) && Pipe_IsSetupOUTReady()))) + { + uint8_t ErrorCode; + + if ((ErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) + return ErrorCode; + + if (!(TimeoutCounter--)) + return HOST_SENDCONTROL_SoftwareTimeOut; + } + + return HOST_SENDCONTROL_Successful; +} + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/HostChapter9.h b/LUFA/Drivers/USB/LowLevel/HostChapter9.h new file mode 100644 index 0000000000..1ca4343a9b --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/HostChapter9.h @@ -0,0 +1,127 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * 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. + */ + +#ifndef __HOSTCHAPTER9_H__ +#define __HOSTCHAPTER9_H__ + + /* Includes: */ + #include + #include + + #include "LowLevel.h" + #include "StdRequestType.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Type Defines: */ + /** Type define for a standard USB control request. + * + * \see StdRequestType.h for information on the request type and data. + * \see The USB 2.0 specification for more information on standard control requests. + */ + typedef struct + { + uint8_t bmRequestType; /**< Type of the request. */ + uint8_t bRequest; /**< Request command code. */ + uint16_t wValue; /**< wValue parameter of the request. */ + uint16_t wIndex; /**< wIndex parameter of the request. */ + uint16_t wLength; /**< Length of the data to transfer in bytes. */ + } USB_Host_Request_Header_t; + + /* Enums: */ + /** Enum for the USB_Host_SendControlRequest() return code, indicating the reason for the error + * if the transfer of the request is unsuccessful. + */ + enum USB_Host_SendControlErrorCodes_t + { + HOST_SENDCONTROL_Successful = 0, /**< No error occurred in the request transfer. */ + HOST_SENDCONTROL_DeviceDisconnect = 1, /**< The attached device was disconnected during the + * request transfer. + */ + HOST_SENDCONTROL_PipeError = 2, /**< An error occured in the pipe while sending the request. */ + HOST_SENDCONTROL_SetupStalled = 3, /**< The attached device stalled the request, usually + * indicating that the request is unsupported on the device. + */ + HOST_SENDCONTROL_SoftwareTimeOut = 4, /**< The request or data transfer timed out. */ + }; + + /* Global Variables: */ + /** Global for the request to send via the USB_Host_SendControlRequest() function. This + * global should be filled with the correct control request data before sending the request to + * the attached device while in host mode. + */ + extern USB_Host_Request_Header_t USB_HostRequest; + + /* Function Prototypes: */ + /** Sends the request stored in the USB_HostRequest global structure to the attached device, + * and transfers the data stored in the buffer to the device, or from the device to the buffer + * as requested. + * + * \param BufferPtr Pointer to the start of the data buffer if the request has a data stage, or + * NULL if the request transfers no data to or from the device. + * + * \return A value from the USB_Host_SendControlErrorCodes_t enum to indicate the result. + */ + uint8_t USB_Host_SendControlRequest(void* BufferPtr); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Enums: */ + enum USB_WaitForTypes_t + { + USB_HOST_WAITFOR_SetupSent, + USB_HOST_WAITFOR_InReceived, + USB_HOST_WAITFOR_OutReady, + }; + + /* Function Prototypes: */ + #if defined(INCLUDE_FROM_HOSTCHAPTER9_C) + static uint8_t USB_Host_Wait_For_Setup_IOS(const uint8_t WaitType); + #endif + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.c b/LUFA/Drivers/USB/LowLevel/LowLevel.c new file mode 100644 index 0000000000..61acf6deff --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/LowLevel.c @@ -0,0 +1,260 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "USBMode.h" + +#include "LowLevel.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 + ) +{ + USB_ShutDown(); + + #if defined(USB_CAN_BE_BOTH) + USB_CurrentMode = Mode; + #endif + + #if !defined(USE_STATIC_OPTIONS) + USB_Options = Options; + #endif + + #if defined(USB_CAN_BE_HOST) + USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; + #endif + + #if defined(USB_DEVICE_ONLY) && defined(USB_FULL_CONTROLLER) + UHWCON |= (1 << UIMOD); + #elif defined(USB_HOST_ONLY) + UHWCON &= ~(1 << UIMOD); + #elif defined(USB_CAN_BE_BOTH) + if (Mode == USB_MODE_UID) + { + UHWCON |= (1 << UIDE); + + USB_INT_Clear(USB_INT_IDTI); + USB_INT_Enable(USB_INT_IDTI); + + USB_CurrentMode = USB_GetUSBModeFromUID(); + } + else if (Mode == USB_MODE_DEVICE) + { + UHWCON |= (1 << UIMOD); + } + else if (Mode == USB_MODE_HOST) + { + UHWCON &= ~(1 << UIMOD); + } + else + { + RAISE_EVENT(USB_PowerOnFail, POWERON_ERROR_NoUSBModeSpecified); + return; + } + #endif + + USB_ResetInterface(); + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) + USB_OTGPAD_On(); + #endif + + USB_IsInitialized = true; + + sei(); +} + +void USB_ShutDown(void) +{ + if (USB_IsConnected) + RAISE_EVENT(USB_Disconnect); + + USB_Detach(); + + USB_INT_DisableAllInterrupts(); + USB_INT_ClearAllInterrupts(); + + USB_IsConnected = false; + USB_IsInitialized = false; + + #if defined(USB_CAN_BE_HOST) + USB_HostState = HOST_STATE_Unattached; + #endif + + #if defined(USB_CAN_BE_DEVICE) + USB_ConfigurationNumber = 0; + #endif + + #if defined(CAN_BE_BOTH) + USB_CurrentMode = USB_MODE_NONE; + #endif + + USB_Interface_Disable(); + USB_PLL_Off(); + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) + USB_OTGPAD_Off(); + #endif + + #if defined(USB_CAN_BE_BOTH) + UHWCON &= ~(1 << UIDE); + #endif +} + +void USB_ResetInterface(void) +{ + USB_INT_DisableAllInterrupts(); + USB_INT_ClearAllInterrupts(); + + USB_IsConnected = false; + + #if defined(USB_CAN_BE_HOST) + USB_HostState = HOST_STATE_Unattached; + #endif + + #if defined(USB_CAN_BE_DEVICE) + USB_ConfigurationNumber = 0; + USB_IsSuspended = false; + USB_RemoteWakeupEnabled = false; + USB_CurrentlySelfPowered = false; + #endif + + if (!(USB_Options & USB_OPT_MANUAL_PLL)) + { + #if defined(USB_MODIFIED_FULL_CONTROLLER) + PLLFRQ = ((1 << PLLUSB) | (1 << PDIV3) | (1 << PDIV1)); + #endif + + USB_PLL_On(); + while (!(USB_PLL_IsReady())); + } + + USB_Interface_Reset(); + + #if defined(USB_CAN_BE_BOTH) + if (UHWCON & (1 << UIDE)) + { + USB_INT_Clear(USB_INT_IDTI); + USB_INT_Enable(USB_INT_IDTI); + USB_CurrentMode = USB_GetUSBModeFromUID(); + } + #endif + + if (!(USB_Options & USB_OPT_REG_DISABLED)) + USB_REG_On(); + + USB_CLK_Unfreeze(); + + #if (defined(USB_CAN_BE_DEVICE) && (defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER))) + if (USB_CurrentMode == USB_MODE_DEVICE) + { + if (USB_Options & USB_DEVICE_OPT_LOWSPEED) + USB_Device_SetLowSpeed(); + else + USB_Device_SetHighSpeed(); + + USB_INT_Enable(USB_INT_VBUS); + } + #endif + + #if (defined(USB_CAN_BE_DEVICE) && !defined(FIXED_CONTROL_ENDPOINT_SIZE)) + if (USB_CurrentMode == USB_MODE_DEVICE) + { + USB_Descriptor_Device_t* DeviceDescriptorPtr; + + if (USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR) + { + #if defined(USE_RAM_DESCRIPTORS) + USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; + #elif defined(USE_EEPROM_DESCRIPTORS) + USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + #else + USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + #endif + } + } + #endif + + USB_Attach(); + + #if defined(USB_DEVICE_ONLY) + USB_INT_Enable(USB_INT_SUSPEND); + USB_INT_Enable(USB_INT_EORSTI); + #elif defined(USB_HOST_ONLY) + USB_Host_HostMode_On(); + + USB_Host_VBUS_Auto_Off(); + USB_OTGPAD_Off(); + + USB_Host_VBUS_Manual_Enable(); + USB_Host_VBUS_Manual_On(); + + USB_INT_Enable(USB_INT_SRPI); + USB_INT_Enable(USB_INT_BCERRI); + #else + if (USB_CurrentMode == USB_MODE_DEVICE) + { + USB_INT_Enable(USB_INT_SUSPEND); + USB_INT_Enable(USB_INT_EORSTI); + } + else if (USB_CurrentMode == USB_MODE_HOST) + { + USB_Host_HostMode_On(); + + USB_Host_VBUS_Auto_Off(); + USB_OTGPAD_Off(); + + USB_Host_VBUS_Manual_Enable(); + USB_Host_VBUS_Manual_On(); + + USB_INT_Enable(USB_INT_SRPI); + USB_INT_Enable(USB_INT_BCERRI); + } + #endif +} diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.h b/LUFA/Drivers/USB/LowLevel/LowLevel.h new file mode 100644 index 0000000000..faafbd7bff --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/LowLevel.h @@ -0,0 +1,371 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Main low level USB driver. This module manages the low level initialization and shut down of the USB AVR's + * USB interface in either device or (if supported) host mode. + */ + +#ifndef __USBLOWLEVEL_H__ +#define __USBLOWLEVEL_H__ + + /* Includes: */ + #include + #include + #include + + #include "USBMode.h" + #include "../../../Common/Common.h" + #include "../HighLevel/Events.h" + #include "../HighLevel/USBTask.h" + #include "../HighLevel/USBInterrupt.h" + + #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) + #include "Host.h" + #include "Pipe.h" + #include "OTG.h" + #endif + + #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) + #include "Device.h" + #include "Endpoint.h" + #include "DevChapter9.h" + #endif + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks and Defines: */ + #if (F_CPU == 8000000) + #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__)) + #define USB_PLL_PSC 0 + #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || \ + defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || \ + defined(__AVR_ATmega32U6__)) + #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) + #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) + #define USB_PLL_PSC 0 + #endif + #elif (F_CPU == 16000000) + #if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_ATmega32U6__)) + #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP1)) + #elif (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)) + #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP0)) + #elif (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__)) + #define USB_PLL_PSC (1 << PLLP0) + #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) + #define USB_PLL_PSC (1 << PINDIV) + #endif + #endif + + #if !defined(USB_PLL_PSC) + #error No PLL prescale value available for chosen F_CPU value and AVR model. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mode mask for the USB_CurrentMode global. This indicates that the USB interface is currently not + * initialized into any mode. + */ + #define USB_MODE_NONE 0 + + /** Mode mask for the USB_CurrentMode global and the USB_Init() function. This indicates that the + * USB interface is or should be initialized in the USB device mode. + */ + #define USB_MODE_DEVICE 1 + + /** Mode mask for the USB_CurrentMode global and the USB_Init() function. This indicates that the + * USB interface is or should be initialized in the USB host mode. + * + * \note Not all USB AVRs support host mode. + */ + #define USB_MODE_HOST 2 + + /** Mode mask for the the USB_Init() function. This indicates that the USB interface should be + * initialized into whatever mode the UID pin of the USB AVR indicates, and that the device + * should swap over its mode when the level of the UID pin changes during operation. + * + * \note Not all USB AVRs support host mode, and thus UID mode. + */ + #define USB_MODE_UID 3 + + /** Regulator disable option mask for USB_Init(). This indicates that the internal 3.3V USB data pad + * regulator should be enabled to regulate the data pin voltages to within the USB standard. + * + * \note See USB AVR data sheet for more information on the internal pad regulator. + */ + #define USB_OPT_REG_DISABLED (1 << 1) + + /** Regulator enable option mask for USB_Init(). This indicates that the internal 3.3V USB data pad + * regulator should be disabled and the AVR's VCC level used for the data pads. + * + * \note See USB AVR data sheet for more information on the internal pad regulator. + */ + #define USB_OPT_REG_ENABLED (0 << 1) + + /** Manual PLL control option mask for USB_Init(). This indicates to the library that the user application + * will take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock + * that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations. + */ + #define USB_OPT_MANUAL_PLL (1 << 2) + + /** Automatic PLL control option mask for USB_Init(). This indicates to the library that the library should + * take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock + * that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations. + */ + #define USB_OPT_AUTO_PLL (0 << 2) + + /** Mask for a CONTROL type endpoint or pipe. + * + * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. + */ + #define EP_TYPE_CONTROL 0b00 + + /** Mask for an ISOCHRONOUS type endpoint or pipe. + * + * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. + */ + #define EP_TYPE_ISOCHRONOUS 0b01 + + /** Mask for a BULK type endpoint or pipe. + * + * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. + */ + #define EP_TYPE_BULK 0b10 + + /** Mask for an INTERRUPT type endpoint or pipe. + * + * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. + */ + #define EP_TYPE_INTERRUPT 0b11 + + /** Mask for determining the type of an endpoint or pipe. This should then be compared with the + * EP_TYPE_* macros elsewhere in this module to determine the exact type of the endpoint or pipe. + * + * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. + */ + #define EP_TYPE_MASK 0b11 + + /** Returns boolean true if the VBUS line is currently high (i.e. the USB host is supplying power), + * otherwise returns false. + */ + #define USB_VBUS_GetStatus() ((USBSTA & (1 << VBUS)) ? true : false) + + /** Detaches the device from the USB bus. This has the effect of removing the device from any + * host if, ceasing USB communications. If no host is present, this prevents any host from + * enumerating the device once attached until USB_Attach() is called. + */ + #define USB_Detach() MACROS{ UDCON |= (1 << DETACH); }MACROE + + /** 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. + */ + #define USB_Attach() MACROS{ UDCON &= ~(1 << DETACH); }MACROE + + #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 acknowedged within this time period, the stream function will fail. + * + * This value may be overridden in the user project makefile as the value of the + * USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch. + */ + #define USB_STREAM_TIMEOUT_MS 100 + #endif + + /* 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 USB interrupts for some of its functionality, this routine will + * enable global interrupts. + * + * Calling this function when the USB interface is already initialized will cause a complete USB + * interface reset and re-enumeration. + * + * \param Mode This is a mask indicating what mode the USB interface is to be initialized to. + * Valid mode masks are USB_MODE_DEVICE, USB_MODE_HOST or USB_MODE_UID. + * + * \param 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 USB_OPT_REG_* mask to control the regulator, a USB_OPT_*_PLL mask to control the + * PLL, and a 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, + * this can be statically set via defining the token USB_DEVICE_ONLY for device mode or + * USB_HOST_ONLY for host mode in the use project makefile, 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. + * + * \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 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. + * + * \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 Device.h for the 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 USB_Init() function. + */ + void USB_ShutDown(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); + + /* Enums: */ + /** Enum for error codes relating to the powering on of the USB interface. These error codes are + * used in the ErrorCode parameter value of the USB_PowerOnFail event. + */ + enum USB_PowerOnErrorCodes_t + { + POWERON_ERROR_NoUSBModeSpecified = 0, /**< Indicates that USB_Init() was called with an + * invalid or missing Mode parameter. + */ + }; + + /* Global Variables: */ + #if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__) + /** Indicates the mode that the USB interface is currently initialized to. This value will be + * one of the 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_CurrentMode; + #endif + + #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__) + extern volatile uint8_t USB_Options; + /** Indicates the current USB options that the USB interface was initialized with when USB_Init() + * was called. This value will be one of the 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. + */ + #endif + + /* Throwable Events: */ + /** This module raises the USB_Disconnect event if the USB interface is reset (such as during a mode + * change while in UID mode) while the USB interface is connected to a device when in host mode, or + * a host while in device mode. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_Disconnect); + + #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) + /** This module raises the Power On Failure event when an error occurs while initializing the USB + * interface. + * + * \see Events.h for more information on this event. + */ + RAISES_EVENT(USB_PowerOnFail); + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define USB_PLL_On() MACROS{ PLLCSR = USB_PLL_PSC; PLLCSR |= (1 << PLLE); }MACROE + #define USB_PLL_Off() MACROS{ PLLCSR = 0; }MACROE + #define USB_PLL_IsReady() ((PLLCSR & (1 << PLOCK)) ? true : false) + + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) + #define USB_REG_On() MACROS{ UHWCON |= (1 << UVREGE); }MACROE + #define USB_REG_Off() MACROS{ UHWCON &= ~(1 << UVREGE); }MACROE + #else + #define USB_REG_On() MACROS{ REGCR &= ~(1 << REGDIS); }MACROE + #define USB_REG_Off() MACROS{ REGCR |= (1 << REGDIS); }MACROE + #endif + + #define USB_OTGPAD_On() MACROS{ USBCON |= (1 << OTGPADE); }MACROE + #define USB_OTGPAD_Off() MACROS{ USBCON &= ~(1 << OTGPADE); }MACROE + + #define USB_CLK_Freeze() MACROS{ USBCON |= (1 << FRZCLK); }MACROE + #define USB_CLK_Unfreeze() MACROS{ USBCON &= ~(1 << FRZCLK); }MACROE + + #define USB_Interface_Enable() MACROS{ USBCON |= (1 << USBE); }MACROE + #define USB_Interface_Disable() MACROS{ USBCON &= ~(1 << USBE); }MACROE + #define USB_Interface_Reset() MACROS{ uint8_t Temp = USBCON; USBCON = (Temp & ~(1 << USBE)); \ + USBCON = (Temp | (1 << USBE)); }MACROE + + /* Inline Functions: */ + static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t USB_GetUSBModeFromUID(void) + { + #if (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__)) + if (USBSTA & (1 << ID)) + return USB_MODE_DEVICE; + else + return USB_MODE_HOST; + #else + return USB_MODE_DEVICE; + #endif + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/OTG.h b/LUFA/Drivers/USB/LowLevel/OTG.h new file mode 100644 index 0000000000..e1a92f1ebb --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/OTG.h @@ -0,0 +1,102 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * 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. + * + * \note These macros are only for AVRs which support the OTG protocol, and do not exist for device-only AVRs. + */ + +#ifndef __USBOTG_H__ +#define __USBOTG_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Initiate a Host Negotiation Protocol request. This indicates to the other connected device + * that the device wishes to change device/host roles. + */ + #define USB_OTG_DEV_Request_HNP() MACROS{ OTGCON |= (1 << HNPREQ); }MACROE + + /** Cancel a Host Negotiation Protocol request. This stops a pending HNP request to the other + * connected device. + */ + #define USB_OTG_DEV_Cancel_HNP_Request() MACROS{ OTGCON &= ~(1 << HNPREQ); }MACROE + + /** Returns boolean false if not currently sending a HNP to the other connected device, or true + * if a HNP is currently being issued. + */ + #define USB_OTG_DEV_IsSendingHNP() ((OTGCON & (1 << HNPREQ)) ? true : false) + + /** Accepts a HNP from a connected device, indicating that both devices should exchange + * device/host roles. + */ + #define USB_OTG_HOST_Accept_HNP() USB_OTG_DEV_Request_HNP() + + /** Rejects a HNP from a connected device, indicating that both devices should remain in their + * current device/host roles. + */ + #define USB_OTG_HOST_Reject_HNP() USB_OTG_DEV_Cancel_HNP_Request() + + /** Returns boolean false if the connected device is not currently sending a HNP request, or true + * if a HNP is currently being issued by the connected device. + */ + #define USB_OTG_HOST_IsHNPReceived() ((OTGCON & (1 << HNPREQ)) ? true : false) + + /** Initiates a Session Request Protocol request. Most OTG devices turn off VBUS when the USB + * interface is not in use, to conserve power. Sending a SRP to a USB OTG device running in + * host mode indicates that VBUS should be applied and a session started. + * + * There are two different methods of sending a SRP - either pulses on the VBUS line, or by + * pulsing the Data + line via the internal pullup resistor. The SRP mode is given as the + * "type" parameter, and can be either USB_OTG_SRP_VBUS or USB_OTG_STP_DATA. + */ + #define USB_OTG_DEV_Initiate_SRP(type) MACROS{ OTGCON = ((OTGCON & ~(1 << SRPSEL)) | (type | (1 << SRPREQ))); }MACROE + + /** Mask for the VBUS pulsing method of SRP, supported by some OTG devices. + * + * \see USB_OTG_DEV_Initiate_SRP() + */ + #define USB_OTG_SRP_VBUS (1 << SRPSEL) + + /** Mask for the Data + pulsing method of SRP, supported by some OTG devices. + * + * \see USB_OTG_DEV_Initiate_SRP() + */ + #define USB_OTG_STP_DATA 0 + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.c b/LUFA/Drivers/USB/LowLevel/Pipe.c new file mode 100644 index 0000000000..743bb91f20 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Pipe.c @@ -0,0 +1,258 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ +#include "USBMode.h" +#if defined(USB_CAN_BE_HOST) + +#define INCLUDE_FROM_PIPE_C +#include "Pipe.h" + +uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; + +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(); + + UPCFG1X = 0; + + UPCFG0X = ((Type << EPTYPE0) | Token | (EndpointNumber << PEPNUM0)); + UPCFG1X = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size)); + + return Pipe_IsConfigured(); +} + +void Pipe_ClearPipes(void) +{ + UPINT = 0; + + for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++) + { + Pipe_ResetPipe(PNum); + Pipe_SelectPipe(PNum); + UPIENX = 0; + UPINTX = 0; + Pipe_ClearError(); + Pipe_ClearErrorFlags(); + Pipe_DeallocateMemory(); + Pipe_DisablePipe(); + } +} + +uint8_t Pipe_WaitUntilReady(void) +{ + uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + + USB_INT_Clear(USB_INT_HSOFI); + + while (!(Pipe_ReadWriteAllowed())) + { + if (Pipe_IsStalled()) + return PIPE_READYWAIT_PipeStalled; + else if (!(USB_IsConnected)) + return PIPE_READYWAIT_DeviceDisconnected; + + if (USB_INT_HasOccurred(USB_INT_HSOFI)) + { + USB_INT_Clear(USB_INT_HSOFI); + + if (!(TimeoutMSRem--)) + return PIPE_READYWAIT_Timeout; + } + } + + return PIPE_READYWAIT_NoError; +} + +uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length +#if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t* DataStream = (uint8_t*)Data; + uint8_t ErrorCode; + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Pipe_ReadWriteAllowed())) + { + Pipe_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Pipe_Write_Byte(*(DataStream++)); + } + + return PIPE_RWSTREAM_ERROR_NoError; +} + +uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length +#if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t* DataStream = (uint8_t*)(Data + Length - 1); + uint8_t ErrorCode; + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Pipe_ReadWriteAllowed())) + { + Pipe_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Pipe_Write_Byte(*(DataStream--)); + } + + return PIPE_RWSTREAM_ERROR_NoError; +} + +uint8_t Pipe_Discard_Stream(uint16_t Length +#if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t ErrorCode; + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Pipe_ReadWriteAllowed())) + { + Pipe_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Pipe_Discard_Byte(); + } + + return PIPE_RWSTREAM_ERROR_NoError; +} + +uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t* DataStream = (uint8_t*)Buffer; + uint8_t ErrorCode; + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Pipe_ReadWriteAllowed())) + { + Pipe_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + *(DataStream++) = Pipe_Read_Byte(); + } + + return PIPE_RWSTREAM_ERROR_NoError; +} + +uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) + , uint8_t (* const Callback)(void) +#endif + ) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); + uint8_t ErrorCode; + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + while (Length--) + { + if (!(Pipe_ReadWriteAllowed())) + { + Pipe_ClearCurrentBank(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_ERROR_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + *(DataStream--) = Pipe_Read_Byte(); + } + + return PIPE_RWSTREAM_ERROR_NoError; +} + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.h b/LUFA/Drivers/USB/LowLevel/Pipe.h new file mode 100644 index 0000000000..a1f28ccc2a --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Pipe.h @@ -0,0 +1,788 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * 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/recieve functions for various datatypes. + */ + +#ifndef __PIPE_H__ +#define __PIPE_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + #include "../HighLevel/USBTask.h" + + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + #include "StreamCallbacks.h" + #endif + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mask for Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */ + #define PIPE_ERRORFLAG_CRC16 (1 << 4) + + /** Mask for Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */ + #define PIPE_ERRORFLAG_TIMEOUT (1 << 3) + + /** Mask for Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */ + #define PIPE_ERRORFLAG_PID (1 << 2) + + /** Mask for Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */ + #define PIPE_ERRORFLAG_DATAPID (1 << 1) + + /** Mask for Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */ + #define PIPE_ERRORFLAG_DATATGL (1 << 0) + + /** Token mask for Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes), + * which will trigger a control request on the attached device when data is written to the pipe. + */ + #define PIPE_TOKEN_SETUP (0b00 << PTOKEN0) + + /** Token mask for Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes), + * indicating that the pipe data will flow from device to host. + */ + #define PIPE_TOKEN_IN (0b01 << PTOKEN0) + + /** Token mask for Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes), + * indicating that the pipe data will flow from host to device. + */ + #define PIPE_TOKEN_OUT (0b10 << PTOKEN0) + + /** Mask for the bank mode selection for the Pipe_ConfigurePipe() macro. This indicates that the pipe + * should have one single bank, which requires less USB FIFO memory but results in slower transfers as + * only one USB device (the AVR or the attached device) can access the pipe's bank at the one time. + */ + #define PIPE_BANK_SINGLE 0 + + /** Mask for the bank mode selection for the Pipe_ConfigurePipe() macro. This indicates that the pipe + * should have two banks, which requires more USB FIFO memory but results in faster transfers as one + * USB device (the AVR or the attached device) can access one bank while the other accesses the second + * bank. + */ + #define PIPE_BANK_DOUBLE (1 << EPBK0) + + /** 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 + + /** Default size of the default control pipe's bank, until altered by the Endpoint0Size value + * in the device descriptor of the attached device. + */ + #define PIPE_CONTROLPIPE_DEFAULT_SIZE 8 + + /** Pipe number mask, for masking against pipe addresses to retrieve the pipe's numerical address + * in the device. + */ + #define PIPE_PIPENUM_MASK 0x07 + + /** Total number of pipes (including the default control pipe at address 0) which may be used in + * the device. Different USB AVR models support different amounts of pipes, this value reflects + * the maximum number of pipes for the currently selected AVR model. + */ + #define PIPE_TOTAL_PIPES 7 + + /** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR + * model supports the largest bank size possible on the device; different pipe numbers support + * different maximum bank sizes. This value reflects the largest possible bank of any pipe on the + * currently selected USB AVR model. + */ + #define PIPE_MAX_SIZE 256 + + /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's + * numerical address in the attached device. + */ + #define PIPE_EPNUM_MASK 0x07 + + /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's + * bank size in the attached device. + */ + #define PIPE_EPSIZE_MASK 0x7FF + + /** Interrupt definition for the pipe IN interrupt (for INTERRUPT type pipes). Should be used with + * the USB_INT_* macros located in USBInterrupt.h. + * + * This interrupt will fire if enabled on an INTERRUPT type pipe if the pipe interrupt period has + * elapsed and the pipe is ready for the next packet from the attached device to be read out from its + * FIFO buffer (if received). + * + * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and + * will fire the common pipe interrupt vector. + * + * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. + */ + #define PIPE_INT_IN UPIENX, (1 << RXINE) , UPINTX, (1 << RXINI) + + /** Interrupt definition for the pipe OUT interrupt (for INTERRUPT type pipes). Should be used with + * the USB_INT_* macros located in USBInterrupt.h. + * + * This interrupt will fire if enabled on an INTERRUPT type endpoint if a the pipe interrupt period + * has elapsed and the pipe is ready for a packet to be written to the pipe's FIFO buffer and sent + * to the attached device (if required). + * + * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and + * will fire the common pipe interrupt vector. + * + * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. */ + #define PIPE_INT_OUT UPIENX, (1 << TXOUTE), UPINTX, (1 << TXOUTI) + + /** Interrupt definition for the pipe SETUP bank ready interrupt (for CONTROL type pipes). Should be + * used with the USB_INT_* macros located in USBInterrupt.h. + * + * This interrupt will fire if enabled on an CONTROL type pipe when the pipe is ready for a new + * control request. + * + * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and + * will fire the common pipe interrupt vector. + * + * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. + */ + #define PIPE_INT_SETUP UPIENX, (1 << TXSTPE) , UPINTX, (1 << TXSTPI) + + /** Interrupt definition for the pipe error interrupt. Should be used with the USB_INT_* macros + * located in USBInterrupt.h. + * + * This interrupt will fire if enabled on a particular pipe if an error occurs on that pipe, such + * as a CRC mismatch error. + * + * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and + * will fire the common pipe interrupt vector. + * + * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. + * + * \see Pipe_GetErrorFlags() for more information on the pipe errors. + */ + #define PIPE_INT_ERROR UPIENX, (1 << PERRE), UPINTX, (1 << PERRI) + + /** Interrupt definition for the pipe NAK received interrupt. Should be used with the USB_INT_* macros + * located in USBInterrupt.h. + * + * This interrupt will fire if enabled on a particular pipe if an attached device returns a NAK in + * response to a sent packet. + * + * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and + * will fire the common pipe interrupt vector. + * + * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. + * + * \see Pipe_IsNAKReceived() for more information on pipe NAKs. + */ + #define PIPE_INT_NAK UPIENX, (1 << NAKEDE), UPINTX, (1 << NAKEDI) + + /** Interrupt definition for the pipe STALL received interrupt. Should be used with the USB_INT_* macros + * located in USBInterrupt.h. + * + * This interrupt will fire if enabled on a particular pipe if an attached device returns a STALL on the + * currently selected pipe. This will also fire if the pipe is an isochronous pipe and a CRC error occurs. + * + * This interrupt must be enabled on *each* pipe which requires it (after the pipe is selected), and + * will fire the common pipe interrupt vector. + * + * \see ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. + */ + #define PIPE_INT_STALL UPIENX, (1 << RXSTALLE), UPINTX, (1 << RXSTALLI) + + /** Indicates the number of bytes currently stored in the current pipe's selected bank. */ + #define Pipe_BytesInPipe() UPBCX + + /** Resets the desired pipe, including the pipe banks and flags. */ + #define Pipe_ResetPipe(pipenum) MACROS{ UPRST = (1 << pipenum); UPRST = 0; }MACROE + + /** Selects the given pipe number. Any pipe operations which do not require the pipe number to be + * indicated will operate on the currently selected pipe. + */ + #define Pipe_SelectPipe(pipenum) MACROS{ UPNUM = pipenum; }MACROE + + /** Returns the pipe address of the currently selected pipe. This is typically used to save the + * currently selected pipe number so that it can be restored after another pipe has been manipulated. + */ + #define Pipe_GetCurrentPipe() (UPNUM & PIPE_PIPENUM_MASK) + + /** Enables the currently selected pipe so that data can be sent and received through it to and from + * an attached device. + * + * \note Pipes must first be configured properly rather than just being enabled via the + * Pipe_ConfigurePipe() macro, which calls Pipe_EnablePipe() automatically. + */ + #define Pipe_EnablePipe() MACROS{ UPCONX |= (1 << PEN); }MACROE + + /** Disables the currently selected pipe so that data cannot be sent and received through it to and + * from an attached device. + */ + #define Pipe_DisablePipe() MACROS{ UPCONX &= ~(1 << PEN); }MACROE + + /** Returns true if the currently selected pipe is enabled, false otherwise. */ + #define Pipe_IsEnabled() ((UPCONX & (1 << PEN)) ? true : false) + + /** Sets the token for the currently selected endpoint to one of the tokens specified by the PIPE_TOKEN_* + * masks. This should only be used on CONTROL type endpoints, to allow for bidirectional transfer of + * data during control requests. + */ + #define Pipe_SetToken(token) MACROS{ UPCFG0X = ((UPCFG0X & ~PIPE_TOKEN_MASK) | token); }MACROE + + /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */ + #define Pipe_SetInfiniteINRequests() MACROS{ UPCONX |= (1 << INMODE); }MACROE + + /** Configures the currently selected pipe to only allow the specified number of IN requests to be + * accepted by the pipe before it is automatically frozen. + */ + #define Pipe_SetFiniteINRequests(n) MACROS{ UPCONX &= ~(1 << INMODE); UPINRQX = n; }MACROE + + /** Returns true if the currently selected pipe is configured, false otherwise. */ + #define Pipe_IsConfigured() ((UPSTAX & (1 << CFGOK)) ? true : false) + + /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds. */ + #define Pipe_SetInterruptPeriod(ms) MACROS{ UPCFG2X = ms; }MACROE + + /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should + * be serviced. + */ + #define Pipe_GetPipeInterrupts() UPINT + + /** Clears the interrupt flag for the specified pipe number. */ + #define Pipe_ClearPipeInterrupt(n) MACROS{ UPINT &= ~(1 << n); }MACROE + + /** Returns true if the specified pipe's interrupt period has elapsed, false otherwise. */ + #define Pipe_HasPipeInterrupted(n) ((UPINT & (1 << n)) ? true : false) + + /** Clears the pipe bank, and switches to the alternate bank if the currently selected pipe is + * dual-banked. When cleared, this either frees the bank up for the next packet from the host + * (if the endpoint is of the OUT direction) or sends the packet contents to the host (if the + * pipe is of the IN direction). + */ + #define Pipe_ClearCurrentBank() MACROS{ UPINTX &= ~(1 << FIFOCON); }MACROE + + /** Unfreezes the pipe, allowing it to communicate with an attached device. */ + #define Pipe_Unfreeze() MACROS{ UPCONX &= ~(1 << PFREEZE); }MACROE + + /** Freezes the pipe, preventing it from communicating with an attached device. */ + #define Pipe_Freeze() MACROS{ UPCONX |= (1 << PFREEZE); }MACROE + + /** Clears the master pipe error flag. */ + #define Pipe_ClearError() MACROS{ UPINTX &= ~(1 << PERRI); }MACROE + + /** Returns true if the master pipe error flag is set for the currently selected pipe, indicating that + * some sort of hardware error has occurred on the pipe. + * + * \see Pipe_GetErrorFlags() macro for information on retreiving the exact error flag. + */ + #define Pipe_IsError() ((UPINTX & (1 << PERRI)) ? true : false) + + /** Clears all the currently selected pipe's hardware error flags, but does not clear the master error + * flag for the pipe. */ + #define Pipe_ClearErrorFlags() MACROS{ UPERRX = 0; }MACROE + + /** Returns a mask of the hardware error flags which have occured on the currently selected pipe. This + * value can then be masked against the PIPE_ERRORFLAG_* masks to determine what error has occurred. + */ + #define Pipe_GetErrorFlags() UPERRX + + /** Returns true if the currently selected pipe may be read from (if data is waiting in the pipe + * bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT + * direction). This function will return false if an error has occured in the pipe, or if the pipe + * is an IN direction and no packet has been received, or if the pipe is an OUT direction and the + * pipe bank is full. + */ + #define Pipe_ReadWriteAllowed() ((UPINTX & (1 << RWAL)) ? true : false) + + /** Clears the flag indicating that a SETUP request has been sent to the attached device from the + * currently selected CONTROL type pipe. + */ + #define Pipe_ClearSetupSent() MACROS{ UPINTX &= ~(1 << TXSTPI); }MACROE + + /** Returns true if no SETUP request is currently being sent to the attached device, false otherwise. */ + #define Pipe_IsSetupSent() ((UPINTX & (1 << TXSTPI)) ? true : false) + + /** Returns true if the currently selected pipe has been stalled by the attached device, false otherwise. */ + #define Pipe_IsStalled() ((UPINTX & (1 << RXSTALLI)) ? true : false) + + /** Clears the stall condition on the currently selected pipe. */ + #define Pipe_ClearStall() MACROS{ UPINTX &= ~(1 << RXSTALLI); }MACROE + + /** Returns true if an IN request has been received on the currently selected CONTROL type pipe, false + * otherwise. + */ + #define Pipe_IsSetupINReceived() ((UPINTX & (1 << RXINI)) ? true : false) + + /** Returns true if the currently selected CONTROL type pipe is ready to send an OUT request, false + * otherwise. + */ + #define Pipe_IsSetupOUTReady() ((UPINTX & (1 << TXOUTI)) ? true : false) + + /** Acknowedges the reception of a setup IN request from the attached device on the currently selected + * CONTROL type endpoint, allowing for the transmission of a setup OUT packet, or the reception of + * another setup IN packet. + */ + #define Pipe_ClearSetupIN() MACROS{ UPINTX &= ~(1 << RXINI); UPINTX &= ~(1 << FIFOCON); }MACROE + + /** Sends the currently selected CONTROL type pipe's contents to the device as a setup OUT packet. */ + #define Pipe_ClearSetupOUT() MACROS{ UPINTX &= ~(1 << TXOUTI); UPINTX &= ~(1 << FIFOCON); }MACROE + + /** Returns true if the device sent a NAK (Negative Acknowedge) in response to the last sent packet on + * the currently selected pipe. This ocurrs when the host sends a packet to the device, but the device + * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been + * received, it must be cleard using Pipe_ClearNAKReceived() before the previous (or any other) packet + * can be re-sent. + */ + #define Pipe_IsNAKReceived() ((UPINTX & (1 << NAKEDI)) ? true : false) + + /** Clears the NAK condition on the currently selected pipe. + * + * \see Pipe_IsNAKReceived() for more details. + */ + #define Pipe_ClearNAKReceived() MACROS{ UPINTX &= ~(1 << NAKEDI); }MACROE + + /* Enums: */ + /** Enum for the possible error return codes of the Pipe_WaitUntilReady function */ + enum Pipe_WaitUntilReady_ErrorCodes_t + { + PIPE_READYWAIT_NoError = 0, /**< Pipe ready for next packet, no error */ + PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */ + PIPE_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while waiting. */ + PIPE_READYWAIT_Timeout = 3, /**< The device failed to accept or send the next packet + * within the software timeout period set by the + * USB_STREAM_TIMEOUT_MS macro. + */ + }; + + /** Enum for the possible error return codes of the Pipe_*_Stream_* functions. */ + enum Pipe_Stream_RW_ErrorCodes_t + { + PIPE_RWSTREAM_ERROR_NoError = 0, /**< Command completed successfully, no error. */ + PIPE_RWSTREAM_ERROR_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */ + PIPE_RWSTREAM_ERROR_DeviceDisconnected = 2, /**< Device was disconnected from the host during + * the transfer. + */ + PIPE_RWSTREAM_ERROR_Timeout = 3, /**< The device failed to accept or send the next packet + * within the software timeout period set by the + * USB_STREAM_TIMEOUT_MS macro. + */ + PIPE_RWSTREAM_ERROR_CallbackAborted = 4, /**< Indicates that the stream's callback function aborted + * the transfer early. + */ + }; + + /* Inline Functions: */ + /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes. */ + static inline uint8_t Pipe_Read_Byte(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Pipe_Read_Byte(void) + { + return UPDATX; + } + + /** Writes one byte from the currently selected pipe's bank, for IN direction pipes. */ + static inline void Pipe_Write_Byte(const uint8_t Byte) + { + UPDATX = Byte; + } + + /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes. */ + static inline void Pipe_Discard_Byte(void) + { + uint8_t Dummy; + + Dummy = UPDATX; + } + + /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT + * direction pipes. + */ + static inline uint16_t Pipe_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT; + static inline uint16_t Pipe_Read_Word_LE(void) + { + uint16_t Data; + + Data = UPDATX; + Data |= (((uint16_t)UPDATX) << 8); + + return Data; + } + + /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT + * direction pipes. + */ + static inline uint16_t Pipe_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT; + static inline uint16_t Pipe_Read_Word_BE(void) + { + uint16_t Data; + + Data = (((uint16_t)UPDATX) << 8); + Data |= UPDATX; + + return Data; + } + + /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN + * direction pipes. + */ + static inline void Pipe_Write_Word_LE(const uint16_t Word) + { + UPDATX = (Word & 0xFF); + UPDATX = (Word >> 8); + } + + /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN + * direction pipes. + */ + static inline void Pipe_Write_Word_BE(const uint16_t Word) + { + UPDATX = (Word >> 8); + UPDATX = (Word & 0xFF); + } + + /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes. */ + static inline void Pipe_Ignore_Word(void) + { + uint8_t Dummy; + + Dummy = UPDATX; + Dummy = UPDATX; + } + + /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT + * direction pipes. + */ + static inline uint32_t Pipe_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT; + static inline uint32_t Pipe_Read_DWord_LE(void) + { + union + { + uint32_t DWord; + uint8_t Bytes[4]; + } Data; + + Data.Bytes[0] = UPDATX; + Data.Bytes[1] = UPDATX; + Data.Bytes[2] = UPDATX; + Data.Bytes[3] = UPDATX; + + return Data.DWord; + } + + /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT + * direction pipes. + */ + static inline uint32_t Pipe_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT; + static inline uint32_t Pipe_Read_DWord_BE(void) + { + union + { + uint32_t DWord; + uint8_t Bytes[4]; + } Data; + + Data.Bytes[3] = UPDATX; + Data.Bytes[2] = UPDATX; + Data.Bytes[1] = UPDATX; + Data.Bytes[0] = UPDATX; + + return Data.DWord; + } + + /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN + * direction pipes. + */ + static inline void Pipe_Write_DWord_LE(const uint32_t DWord) + { + Pipe_Write_Word_LE(DWord); + Pipe_Write_Word_LE(DWord >> 16); + } + + /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN + * direction pipes. + */ + static inline void Pipe_Write_DWord_BE(const uint32_t DWord) + { + Pipe_Write_Word_BE(DWord >> 16); + Pipe_Write_Word_BE(DWord); + } + + /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes. */ + static inline void Pipe_Ignore_DWord(void) + { + uint8_t Dummy; + + Dummy = UPDATX; + Dummy = UPDATX; + Dummy = UPDATX; + Dummy = UPDATX; + } + + /* External Variables: */ + /** Global indicating the maximum packet size of the default control pipe located at address + * 0 in the device. This value is set to the value indicated in the attached device's device + * descriptor once the USB interface is initialized into host mode and a device is attached + * to the USB bus. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + extern uint8_t USB_ControlPipeSize; + + /* Function Prototypes: */ + /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the + * attached device, bank size and banking mode. Pipes should be allocated in ascending order by their + * address in the device (i.e. pipe 1 should be configured before pipe 2 and so on). + * + * The pipe type may be one of the EP_TYPE_* macros listed in LowLevel.h, the token may be one of the + * PIPE_TOKEN_* masks. + * + * The bank size must indicate the maximum packet size that the pipe can handle. Different pipe + * numbers can handle different maximum packet sizes - refer to the chosen USB AVR's datasheet to + * determine the maximum bank size for each pipe. + * + * The banking mode may be either PIPE_BANK_SINGLE or PIPE_BANK_DOUBLE. + * + * A newly configured pipe is frozen by default, and must be unfrozen before use via the Pipe_Unfreeze() macro. + * + * \note This routine will select the specified pipe, and the pipe will remain selected once the + * routine completes regardless of if the pipe configuration succeeds. + * + * \return Boolean true if the configuration is successful, false otherwise + */ + 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); + + /** Spinloops until the currently selected non-control pipe is ready for the next packed of data + * to be read or written to it. + * + * \note This routine should not be called on CONTROL type pipes. + * + * \return A value from the Pipe_WaitUntilReady_ErrorCodes_t enum. + */ + uint8_t Pipe_WaitUntilReady(void); + + /** Writes the given number of bytes to the pipe from the given buffer in little endian, + * sending full packets to the device as needed. The last packet filled is not automatically sent; + * the user is responsible for manually sending the last written packet to the host via the + * Pipe_ClearCurrentBank() macro. Between each USB packet, the given stream callback function is + * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \param Buffer Pointer to the source data buffer to read from. + * \param Length Number of bytes to read for the currently selected pipe into the buffer. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_LE(const void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ) ATTR_NON_NULL_PTR_ARG(1); + + /** Writes the given number of bytes to the pipe from the given buffer in big endian, + * sending full packets to the device as needed. The last packet filled is not automatically sent; + * the user is responsible for manually sending the last written packet to the host via the + * Pipe_ClearCurrentBank() macro. Between each USB packet, the given stream callback function is + * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \param Buffer Pointer to the source data buffer to read from. + * \param Length Number of bytes to read for the currently selected pipe into the buffer. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_BE(const void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host + * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the + * user is responsible for manually discarding the last packet from the host via the Pipe_ClearCurrentBank() macro. + * Between each USB packet, the given stream callback function is executed repeatedly until the next packet is ready, + * allowing for early aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \param Length Number of bytes to send via the currently selected pipe. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Discard_Stream(uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ); + + /** Reads the given number of bytes from the pipe into the given buffer in little endian, + * sending full packets to the device as needed. The last packet filled is not automatically sent; + * the user is responsible for manually sending the last written packet to the host via the + * Pipe_ClearCurrentBank() macro. Between each USB packet, the given stream callback function is + * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \param Buffer Pointer to the source data buffer to write to. + * \param Length Number of bytes to read for the currently selected pipe to read from. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads the given number of bytes from the pipe into the given buffer in big endian, + * sending full packets to the device as needed. The last packet filled is not automatically sent; + * the user is responsible for manually sending the last written packet to the host via the + * Pipe_ClearCurrentBank() macro. Between each USB packet, the given stream callback function is + * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers. + * + * The callback routine should be created using the STREAM_CALLBACK() macro. If the token + * NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled + * and this function has the Callback parameter ommitted. + * + * \param Buffer Pointer to the source data buffer to write to. + * \param Length Number of bytes to read for the currently selected pipe to read from. + * \param Callback Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + , uint8_t (* const Callback)(void) + #endif + ) ATTR_NON_NULL_PTR_ARG(1); + + /* Function Aliases: */ + /** Alias for Pipe_Discard_Byte(). + */ + #define Pipe_Ignore_Byte() Pipe_Discard_Byte() + + /** Alias for Pipe_Discard_Word(). + */ + #define Pipe_Ignore_Word() Pipe_Discard_Word() + + /** Alias for Pipe_Discard_DWord(). + */ + #define Pipe_Ignore_DWord() Pipe_Discard_DWord() + + /** Alias for Pipe_Read_Word_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Pipe_Read_Word() Pipe_Read_Word_LE() + + /** Alias for Pipe_Write_Word_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Pipe_Write_Word(Word) Pipe_Write_Word_LE(Word) + + /** Alias for Pipe_Read_DWord_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Pipe_Read_DWord() Pipe_Read_DWord_LE() + + /** Alias for Pipe_Write_DWord_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #define Pipe_Write_DWord(DWord) Pipe_Write_DWord_LE(DWord) + + /** Alias for Pipe_Read_Stream_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #if !defined(NO_STREAM_CALLBACKS) + #define Pipe_Read_Stream(Buffer, Length, Callback) Pipe_Read_Stream_LE(Buffer, Length, Callback) + #else + #define Pipe_Read_Stream(Buffer, Length) Pipe_Read_Stream_LE(Buffer, Length) + #endif + + /** Alias for Pipe_Write_Stream_LE(). By default USB transfers use little endian format, thus + * the command with no endianness specifier indicates little endian mode. + */ + #if !defined(NO_STREAM_CALLBACKS) + #define Pipe_Write_Stream(Buffer, Length, Callback) Pipe_Read_Stream_LE(Buffer, Length, Callback) + #else + #define Pipe_Write_Stream(Buffer, Length) Pipe_Read_Stream_LE(Buffer, Length) + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define PIPE_TOKEN_MASK (0x03 << PTOKEN0) + + #define Pipe_AllocateMemory() MACROS{ UPCFG1X |= (1 << ALLOC); }MACROE + #define Pipe_DeallocateMemory() MACROS{ UPCFG1X &= ~(1 << ALLOC); }MACROE + + /* Function Prototypes: */ + void Pipe_ClearPipes(void); + + /* Inline Functions: */ + static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYSINLINE; + static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes) + { + if (Bytes <= 8) + return (0 << EPSIZE0); + else if (Bytes <= 16) + return (1 << EPSIZE0); + else if (Bytes <= 32) + return (2 << EPSIZE0); + else if (Bytes <= 64) + return (3 << EPSIZE0); + else if (Bytes <= (8 << 4)) + return (4 << EPSIZE0); + else + return (5 << EPSIZE0); + }; + + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/StdRequestType.h b/LUFA/Drivers/USB/LowLevel/StdRequestType.h new file mode 100644 index 0000000000..02d4fdc58d --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/StdRequestType.h @@ -0,0 +1,191 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Contains definitions for the various control request parameters, so that the request details (such as data + * direction, request recipient, etc.) can be extracted via masking. + */ + +#ifndef __STDREQTYPE_H__ +#define __STDREQTYPE_H__ + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mask for the request type parameter, to indicate the direction of the request data (Host to Device + * or Device to Host). The result of this mask should then be compared to the request direction masks. + * + * \see REQDIR_* macros for masks indicating the request data direction. + */ + #define CONTROL_REQTYPE_DIRECTION 0b10000000 + + /** Mask for the request type parameter, to indicate the type of request (Device, Class or Vendor + * Specific). The result of this mask should then be compared to the request type masks. + * + * \see REQTYPE_* macros for masks indicating the request type. + */ + #define CONTROL_REQTYPE_TYPE 0b01100000 + + /** Mask for the request type parameter, to indicate the recipient of the request (Standard, Class + * or Vendor Specific). The result of this mask should then be compared to the request recipient + * masks. + * + * \see REQREC_* macros for masks indicating the request recipient. + */ + #define CONTROL_REQTYPE_RECIPIENT 0b00011111 + + /** Request data direction mask, indicating that the request data will flow from host to device. + * + * \see CONTROL_REQTYPE_DIRECTION macro. + */ + #define REQDIR_HOSTTODEVICE (0 << 7) + + /** Request data direction mask, indicating that the request data will flow from device to host. + * + * \see CONTROL_REQTYPE_DIRECTION macro. + */ + #define REQDIR_DEVICETOHOST (1 << 7) + + /** Request type mask, indicating that the request is a standard request. + * + * \see CONTROL_REQTYPE_TYPE macro. + */ + #define REQTYPE_STANDARD (0 << 5) + + /** Request type mask, indicating that the request is a class-specific request. + * + * \see CONTROL_REQTYPE_TYPE macro. + */ + #define REQTYPE_CLASS (1 << 5) + + /** Request type mask, indicating that the request is a vendor specific request. + * + * \see CONTROL_REQTYPE_TYPE macro. + */ + #define REQTYPE_VENDOR (2 << 5) + + /** Request recipient mask, indicating that the request is to be issued to the device as a whole. + * + * \see CONTROL_REQTYPE_RECIPIENT macro. + */ + #define REQREC_DEVICE (0 << 0) + + /** Request recipient mask, indicating that the request is to be issued to an interface in the + * currently selected configuration. + * + * \see CONTROL_REQTYPE_RECIPIENT macro. + */ + #define REQREC_INTERFACE (1 << 0) + + /** Request recipient mask, indicating that the request is to be issued to an endpoint in the + * currently selected configuration. + * + * \see CONTROL_REQTYPE_RECIPIENT macro. + */ + #define REQREC_ENDPOINT (2 << 0) + + /** Request recipient mask, indicating that the request is to be issued to an unspecified element + * in the currently selected configuration. + * + * \see CONTROL_REQTYPE_RECIPIENT macro. + */ + #define REQREC_OTHER (3 << 0) + + /** Feature indicator for Clear Feature or Set Feature commands. When used in a Clear Feature + * request this indicates that an endpoint (whose address is given elsewhere in the request + * should have its stall condition cleared. If used in a similar manner inside a Set Feature + * request, this stalls an endpoint. + */ + #define FEATURE_ENDPOINT_HALT 0x00 + + /** Feature indicator for Clear Feature or Set Feature commands. When used in a Clear Feature + * request this indicates that the remote wakeup enabled device should not issue remote + * wakeup requests until further notice. If used in a similar manner inside a Set Feature + * request, this re-enabled the remote wakeup feature on the device. + */ + #define FEATURE_REMOTE_WAKEUP 0x01 + + /* Enums: */ + /** Enumeration for the various standard request commands. These commands are applicable when the + * request type is REQTYPE_STANDARD (with the exception of REQ_GetDescriptor, which is always + * handled regardless of the request type value). + * + * \see Chapter 9 of the USB 2.0 Specification. + */ + enum USB_Control_Request_t + { + REQ_GetStatus = 0, /**< Implemented in the library for device, endpoint and interface + * recipients. Passed to the user application for other recipients + * via the USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_ClearFeature = 1, /**< Implemented in the library for device, endpoint and interface + * recipients. Passed to the user application for other recipients + * via the USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_SetFeature = 3, /**< Implemented in the library for device, endpoint and interface + * recipients. Passed to the user application for other recipients + * via the USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_SetAddress = 5, /**< Implemented in the library for the device recipient. Passed + * to the user application for other recipients via the + * USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_GetDescriptor = 6, /**< Implemented in the library for all recipients and all request + * types. */ + REQ_SetDescriptor = 7, /**< Not implemented in the library, passed to the user application + * via the USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_GetConfiguration = 8, /**< Implemented in the library for the device recipient. Passed + * to the user application for other recipients via the + * USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_SetConfiguration = 9, /**< Implemented in the library for the device recipient. Passed + * to the user application for other recipients via the + * USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_GetInterface = 10, /**< Not implemented in the library, passed to the user application + * via the USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_SetInterface = 11, /**< Not implemented in the library, passed to the user application + * via the USB_UnhandledControlPacket() event when received in + * device mode. */ + REQ_SynchFrame = 12, /**< Not implemented in the library, passed to the user application + * via the USB_UnhandledControlPacket() event when received in + * device mode. */ + }; + +/* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define FEATURE_SELFPOWERED_ENABLED (1 << 0) + #define FEATURE_REMOTE_WAKEUP_ENABLED (1 << 1) + #endif + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/StreamCallbacks.h b/LUFA/Drivers/USB/LowLevel/StreamCallbacks.h new file mode 100644 index 0000000000..60e408e9cf --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/StreamCallbacks.h @@ -0,0 +1,87 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Macros and enums for the stream callback routines in Endpoint.h and Pipe.c. This module contains the + * code required to easily set up stream callback functions which can be used to force early abort of a + * stream read/write process. + */ + +#ifndef __STREAMCALLBACK_H__ +#define __STREAMCALLBACK_H__ + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Creates a prototype for or begins a stream callback routine. Stream callback routines are small + * routines which are executed during stream read or writes (if the callback-enabled versions of + * these functions are used) which allow the user application to abort the transfer when certain + * arbitrary conditions are met. + * + * Stream callback functions should return a value from the StreamCallback_Return_ErrorCodes_t + * enum. + * + * Usage Example (Device Endpoint, but applicable for Host pipes also): + * \code + * STREAM_CALLBACK(GlobalNotSet); // Callback Prototype + * + * STREAM_CALLBACK(GlobalNotSet) + * { + * if (MyGlobal == false) + * return ENDPOINT_STREAMCALLBACK_Continue; + * else + * return ENDPOINT_STREAMCALLBACK_Abort; + * } + * + * //... + * // Inside some routine: + * if (Endpoint_Write_CStream_LE(DataBuffer, sizeof(DataBuffer), GlobalNotSet) == + * ENDPOINT_RWSTREAM_ERROR_CallbackAborted) + * { + * // Do something when the callback aborted the transfer early + * } + * \endcode + */ + #define STREAM_CALLBACK(name) uint8_t name (void) + + /** Used with the Endpoint and Pipe stream functions as the callback function parameter, indicating that the stream + * call has no callback function to be called between USB packets. + */ + #define NO_STREAM_CALLBACK NULL + + /* Enums: */ + /** Enum for the possible error return codes of a stream callback function */ + enum StreamCallback_Return_ErrorCodes_t + { + STREAMCALLBACK_Continue = 0, /**< Continue sending or receiving the stream. */ + STREAMCALLBACK_Abort = 1, /**< Abort the stream send or reciving process. */ + }; + +#endif diff --git a/LUFA/Drivers/USB/LowLevel/USBMode.h b/LUFA/Drivers/USB/LowLevel/USBMode.h new file mode 100644 index 0000000000..f0fbf68df6 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/USBMode.h @@ -0,0 +1,77 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#ifndef __USBMODE_H__ +#define __USBMODE_H__ + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #if ((defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \ + defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB82__) || \ + defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \ + defined(__AVR_ATmega32U6__)) && !defined(USB_DEVICE_ONLY)) + #define USB_DEVICE_ONLY + #endif + + #if (defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB82__)) + #define USB_LIMITED_CONTROLLER + #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) + #define USB_MODIFIED_FULL_CONTROLLER + #else + #define USB_FULL_CONTROLLER + #endif + + #if (!defined(USB_DEVICE_ONLY) && !defined(USB_HOST_ONLY)) + #define USB_CAN_BE_BOTH + #define USB_CAN_BE_HOST + #define USB_CAN_BE_DEVICE + #elif defined(USB_HOST_ONLY) + #define USB_CAN_BE_HOST + #define USB_CurrentMode USB_MODE_HOST + #elif defined(USB_DEVICE_ONLY) + #define USB_CAN_BE_DEVICE + #define USB_CurrentMode USB_MODE_DEVICE + #endif + + #if (defined(USB_HOST_ONLY) && defined(USB_DEVICE_ONLY)) + #error USB_HOST_ONLY and USB_DEVICE_ONLY are mutually exclusive. + #endif + + #if (defined(USB_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)) + #error USB_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. + #endif + + #if defined(USE_STATIC_OPTIONS) + #define USB_Options USE_STATIC_OPTIONS + #endif + #endif + +#endif diff --git a/LUFA/Drivers/USB/USB.h b/LUFA/Drivers/USB/USB.h new file mode 100644 index 0000000000..e90d397ce3 --- /dev/null +++ b/LUFA/Drivers/USB/USB.h @@ -0,0 +1,83 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Master include file for the library USB functionality. This file should be included in all user projects making + * use of the USB portions of the library, instead of including any headers in the USB/LowLevel or USB/HighLevel + * directories. + * + * Class specific utility files in USB/Class/ must still be included manually, as they are not normally part of + * the USB library unless desired by the library user. + */ + +#ifndef __USB_H__ +#define __USB_H__ + + /* Preprocessor Checks: */ + #if (!(defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__)) && defined(USB_HOST_ONLY)) + #error USB_HOST_ONLY is not available for the currently selected USB AVR model. + #endif + + #if (!(defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \ + defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \ + defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB82__) || \ + defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \ + defined(__AVR_ATmega32U6__))) + #error The currently selected AVR model is not supported under the USB component of the LUFA library. + #endif + + /* Includes: */ + #include "LowLevel/USBMode.h" + + #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) + #include "LowLevel/Host.h" + #include "LowLevel/HostChapter9.h" + #include "LowLevel/Pipe.h" + #endif + + #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) + #include "LowLevel/Device.h" + #include "LowLevel/DevChapter9.h" + #include "LowLevel/Endpoint.h" + #endif + + #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) + #include "LowLevel/OTG.h" + #endif + + #include "LowLevel/LowLevel.h" + #include "HighLevel/USBTask.h" + #include "HighLevel/USBInterrupt.h" + #include "HighLevel/Events.h" + #include "HighLevel/StdDescriptors.h" + +#endif + diff --git a/LUFA/GettingStarted.txt b/LUFA/GettingStarted.txt new file mode 100644 index 0000000000..0fe3f50b92 --- /dev/null +++ b/LUFA/GettingStarted.txt @@ -0,0 +1,117 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \page Page_GettingStarted Getting Started + * + * Out of the box, LUFA contains a large number of pre-made class demos for you to test, experiment with and + * ultimately build upon for your own projects. All the demos come pre-configured to build and run correctly + * on the AT90USB1287 AVR microcontroller, mounted on the Atmel USBKEY board and running at an 8MHz master clock. + * This is due to two reasons; one, it is the hardware the author posesses, and two, it is the most popular Atmel + * USB demonstration board to date. + * + * \section Sec_Prerequisites Prerequisites + * Before you can compile any of the LUFA library code or demos, you will need a recent distribution of avr-libc (1.6.2+) + * and the AVR-GCC (4.2+) compiler. For Windows users, the best way to obtain these is the WinAVR project + * (http://winavr.sourceforge.net) as this provides a single-file setup for everything required to compile your + * own AVR projects. + * + * \section Sec_Configuring Configuring the Demos, Bootloaders and Projects + * If the target AVR model, clock speed, board or other settings are different to the current settings, they must be changed + * and the project recompiled from the source code before being programmed into the AVR microcontroller. Most project + * configuration options are located in the "makefile" build script inside each LUFA application's folder, however some + * demo or application-specific configuration settings (such as the output format in the AudioOut demo) are located in the + * main .c source file of the project. + * + * Each project "makefile" contains all the script and configuration data required to compile each project. When opened with + * any regular basic text editor such as Notepad or Wordpad (ensure that the save format is a pure ASCII text format) the + * build configuration settings may be altered. + * + * Inside each makefile, a number of configuration variables are located, with the format " = ". For + * each application, the important variables which should be altered are: + * + * - MCU, the target AVR processor. + * - BOARD, the target board hardware + * - F_CPU, the target AVR master clock frequency + * - CDEFS, the C preprocessor defines which configure the source code + * + * These values should be changed to reflect the build hardware. + * + * \subsection SSec_MCU The MCU Parameter + * This parameter indicates the target AVR model for the compiled application. This should be set to the model of the target AVR + * (such as the AT90USB1287, or the ATMEGA32U4), in all lower-case (e.g. "at90usb1287"). Note that not all demos support all the + * USB AVR models, as they may make use of peripherals or modes only present in some devices. + * + * For supported library AVR models, see main documentation page. + * + * \subsection SSec_BOARD The BOARD Parameter + * This parameter indicates the target AVR board hardware for the compiled application. Some LUFA library drivers are board-specific, + * such as the LED driver, and the library needs to know the layout of the target board. If you are using one of the board models listed + * on the main library page, change this parameter to the board name in all UPPER-case. + * + * If you are not using any board-specific drivers in the LUFA library, or you are using a custom board layout, change this to read + * "USER" (no quotes) instead of a standard board name. If the USER board type is selected and the application makes use of one or more + * board-specific hardware drivers inside the LUFA library, then the appropriate stub drives files should be copied from the /BoardStubs/ + * directory into a /Board/ folder inside the application directory, and the stub driver completed with the appropriate code to drive the + * custom board's hardware. + * + * \subsection SSec_F_CPU The F_CPU Parameter + * This parameter indicates the target AVR's master clock frequency, in Hz. Consult your AVR model's datasheet for allowable clock frequencies + * if the USB interface is to be operational. + * + * Note that this value does not actually *alter* the AVR's clock frequency, it is just a way to indicate to the library the clock frequency + * of the AVR as set by the AVR's fuses. If this value does not reflect the actual running frequency of the AVR, incorrect operation of one of more + * library components will ocurr. + * + * \subsection SSec_CDEFS The CDEFS Parameter + * Most applications will actually have multiple CDEF lines, which are concatenated together with the "+=" operator. This ensures that large + * numbers of configuration options remain readable by splitting up groups of options into seperate lines. + * + * Normally, these options do not need to be altered to allow an application to compile and run correctly on a different board or AVR to the + * current configuration - if the options are incorrect, then the demo is most likely incompatible with the chosen USB AVR model and cannot be + * made to function through the altering of the makefile settings alone (or at all). Settings such as the USB mode (device, host or both), the USB + * interface speed (Low or Full speed) and other LUFA configuration options can be set here - refer to the library documentation for details on the + * configuration parameters. + * + * \section Sec_Compiling Compiling a LUFA Application + * Compiling the LUFA demos, applications and/or bootloaders is very simple. LUFA comes with makefile scripts for + * each individual demo, bootloader and project folder, as well as scripts in the /Demos/, /Bootloaders/, /Projects/ + * and the LUFA root directory. This means that compilation can be started from any of the above directories, with + * a build started from an upper directory in the directory structure executing build of all child directories under it. + * This means that while a build inside a particular demo directory will build only that particular demo, a build stated + * from the /Demos/ directory will build all LUFA demo projects sequentially. + * + * \subsection SSec_CommandLine Via the Command Line + * To build a project from the source via the command line, the command "make all" should be executed from the command line in the directory + * of interest. To remove compiled files (including the binary output, all intermediatary files and all diagnostic output + * files), execute "make clean". Once a "make all" has been run and no errors were encountered, the resulting binary will + * be located in the generated ".HEX" file. If your project makes use of pre-initialized EEPROM variables, the generated ".EEP" + * file will contain the project's EEPROM data. + * + * \subsection SSec_AVRStudio Via AVRStudio + * Each demo, project and bootloader contains an AVRStudio project (.aps) which can be used to build each project. Once opened + * in AVRStudio, the project can be built and cleaned using the GUI buttons or menus. Note that the AVRStudio project files make + * use of the external project makefile, thus the procedure for configuring a demo remains the same regardless of the build environment. + * + * \section Sec_Programming Programming a USB AVR + * Once you have built an application, you will need a way to program in the resulting ".HEX" file (and, if your + * application uses EEPROM variables with initial values, also a ".EEP" file) into your USB AVR. Normally, the + * reprogramming an AVR device must be performed using a special piece of programming hardware, through one of the + * supported AVR programming protocols - ISP, HVSP, HVPP, JTAG or dW. This can be done through a custom programmer, + * a third party programmer, or an official Atmel AVR tool - for more information, see the Atmel.com website. + * + * Alternatively, you can use the bootloader. From the Atmel factory, each USB AVR comes preloaded with the Atmel + * DFU (Device Firmware Update) class bootloader, a small piece of AVR firmware which allows the remainder of the + * AVR to be programmed through a non-standard interface such as the serial USART port, SPI, or (in this case) USB. + * Bootloaders have the advantage of not requiring any special hardware for programming, and cannot usually be erased + * or broken without an external programming device. They have disadvantages however; they cannot change the fuses of + * the AVR (special configuration settings that control the operation of the chip itself) and a small portion of the + * AVR's FLASH program memory must be reserved to contain the bootloader firmware, and thus cannot be used by the + * loaded application. Atmel's DFU bootloader is either 4KB (for the smaller USB AVRs) or 8KB (for the larger USB AVRs). + * + * If you wish to use the DFU bootloader to program in your application, refer to your DFU programmer's documentation. + * Atmel provides a free utility called FLIP which is USB AVR compatible, and an open source (Linux compatible) + * alternative exists called "dfu-programmer". + */ diff --git a/LUFA/MainPage.txt b/LUFA/MainPage.txt new file mode 100644 index 0000000000..e5909f7edd --- /dev/null +++ b/LUFA/MainPage.txt @@ -0,0 +1,75 @@ +/** \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 About the LUFA (Formerly MyUSB) Library + * + * Lightweight USB Framework for AVRs Library, written by Dean Camera. + * + * \section Sec_About About this library + * + * Originally based on the AT90USBKEY from Atmel, it is an open-source, driver for the USB-enabled AVR + * microcontrollers, released under the MIT license. Currently, the AT90USB1286, AT90USB1287, AT90USB646, + * AT90USB647, AT90USB162, AT90USB82, ATMEGA16U4, ATMEGA32U6 and ATMEGA32U4 AVR microcontrollers are supported by the + * library. Supported premade boards are the USBKEY, STK525, STK526, RZUSBSTICK and ATAVRUSBRF01. + * + * The library is currently in a stable release, suitable for download and incorporation into user projects for + * both host and device modes. For information about the project progression, check out my blog. + * + * LUFA is written specifically for the free AVR-GCC compiler, and uses several GCC-only extensions to make the + * library API more streamlined and robust. You can download AVR-GCC for free in a convenient windows package, + * from the the WinAVR website. + * + * \section Sec_Links Library Links + * Project Homepage: http://www.fourwalledcubicle.com/LUFA.php \n + * Development Blog: http://www.fourwalledcubicle.com/blog \n + * Discussion Group: http://groups.google.com/group/myusb-support-list \n + * SVN Access, Bug Reports and Feature Requests: http://code.google.com/p/lufa-lib/ \n + * Author's Website: http://www.fourwalledcubicle.com \n + * + * WinAVR Website: http://winavr.sourceforge.net \n + * avr-libc Website: http://www.nongnu.org/avr-libc/ \n + * + * USB-IF Website: http://www.usb.org \n + * + * \section Sec_License License + * The LUFA library is currently released under the MIT licence, included below. + * + * \verbatim + * 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. + * \endverbatim + * + * \section Sec_Demos Demos and Bootloaders + * The LUFA library ships with several different host and device demos, located in the /Demos/ subdirectory. + * If this directory is missing, please re-download the project from the project homepage. + * + * Also included with the library are two fully functional bootloaders, loacated in the /Bootloaders/ subdirectory. + * The DFU class bootloader is compatible with Atmel's FLIP software or the open source dfu-programmer project, and + * the CDC class (AVR109 protocol) is compatible with such open source software as AVRDUDE and AVR-OSP. + * + * \section Sec_Donations Donate + * I am a 20 year old University student studying for a double degree in Computer Science and Electronics + * Engineering. This leaves little time for any sort of work or leisure. Please consider donating a small amount + * to myself to support this and my future Open Source projects. You can donate any amount via PayPal on my + * website, http://www.fourwalledcubicle.com . All donations are greatly appreciated. + */ + \ No newline at end of file diff --git a/LUFA/MemoryAllocator/DynAlloc.c b/LUFA/MemoryAllocator/DynAlloc.c new file mode 100644 index 0000000000..a91e0f35e8 --- /dev/null +++ b/LUFA/MemoryAllocator/DynAlloc.c @@ -0,0 +1,226 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#define INCLUDE_FROM_DYNALLOC_C +#include "DynAlloc.h" + +struct +{ + char Mem_Heap[NUM_BLOCKS * BLOCK_SIZE]; + void* Mem_Handles[NUM_HANDLES]; + uint8_t Mem_Block_Flags[(NUM_BLOCKS / 4) + ((NUM_BLOCKS % 4) ? 1 : 0)]; + uint8_t FlagMaskLookupMask[4]; + uint8_t FlagMaskLookupNum[4]; +} Mem_MemData = {FlagMaskLookupMask: {(3 << 0), (3 << 2), (3 << 4), (3 << 6)}, + FlagMaskLookupNum: { 0, 2, 4, 6}}; + +static uint8_t Mem_GetBlockFlags(const Block_Number_t BlockNum) +{ + const Block_Number_t BlockIndex = (BlockNum >> 2); + const uint8_t FlagMask = Mem_MemData.FlagMaskLookupMask[BlockNum & 0x03]; + const uint8_t FlagMaskShift = Mem_MemData.FlagMaskLookupNum[BlockNum & 0x03]; + + return ((Mem_MemData.Mem_Block_Flags[BlockIndex] & FlagMask) >> FlagMaskShift); +} + +static void Mem_SetBlockFlags(const Block_Number_t BlockNum, const uint8_t Flags) +{ + const Block_Number_t BlockIndex = (BlockNum >> 2); + const uint8_t FlagMask = Mem_MemData.FlagMaskLookupMask[BlockNum & 0x03]; + const uint8_t FlagMaskShift = Mem_MemData.FlagMaskLookupNum[BlockNum & 0x03]; + + Mem_MemData.Mem_Block_Flags[BlockIndex] &= ~FlagMask; + Mem_MemData.Mem_Block_Flags[BlockIndex] |= (Flags << FlagMaskShift); +} + +static inline void Mem_Defrag(void) +{ + Block_Number_t FreeStartBlock = 0; + char* FreeStartPtr = NULL; + char* UsedStartPtr = NULL; + Block_Number_t CurrBlock; + + for (CurrBlock = 0; CurrBlock < NUM_BLOCKS; CurrBlock++) + { + if (!(Mem_GetBlockFlags(CurrBlock) & BLOCK_USED_MASK)) + { + FreeStartPtr = &Mem_MemData.Mem_Heap[CurrBlock * BLOCK_SIZE]; + FreeStartBlock = CurrBlock; + break; + } + } + + if (FreeStartPtr == NULL) + return; + + while (++CurrBlock < NUM_BLOCKS) + { + uint8_t CurrBlockFlags = Mem_GetBlockFlags(CurrBlock); + + if (CurrBlockFlags & BLOCK_USED_MASK) + { + UsedStartPtr = &Mem_MemData.Mem_Heap[CurrBlock * BLOCK_SIZE]; + + for (Handle_Number_t HandleNum = 0; HandleNum < NUM_HANDLES; HandleNum++) + { + if (Mem_MemData.Mem_Handles[HandleNum] == UsedStartPtr) + { + Mem_MemData.Mem_Handles[HandleNum] = FreeStartPtr; + break; + } + } + + memcpy(FreeStartPtr, UsedStartPtr, BLOCK_SIZE); + FreeStartPtr += BLOCK_SIZE; + + Mem_SetBlockFlags(FreeStartBlock++, CurrBlockFlags); + Mem_SetBlockFlags(CurrBlock, 0); + } + } +} + +static inline bool Mem_FindFreeBlocks(Block_Number_t* const RetStartPtr, const Block_Number_t Blocks) +{ + Block_Number_t FreeInCurrSec = 0; + + for (Block_Number_t CurrBlock = 0; CurrBlock < NUM_BLOCKS; CurrBlock++) + { + if (Mem_GetBlockFlags(CurrBlock) & BLOCK_USED_MASK) + FreeInCurrSec = 0; + else + FreeInCurrSec++; + + if (FreeInCurrSec >= Blocks) + { + *RetStartPtr = CurrBlock; + return true; + } + } + + return false; +} + +Mem_Handle_t Mem_Alloc(const Alloc_Size_t Bytes) +{ + Block_Number_t ReqBlocks = (Bytes / BLOCK_SIZE); + Block_Number_t StartBlock; + + if (Bytes % BLOCK_SIZE) + ReqBlocks++; + + if (!(Mem_FindFreeBlocks(&StartBlock, ReqBlocks))) + { + Mem_Defrag(); + + if (!(Mem_FindFreeBlocks(&StartBlock, ReqBlocks))) + return NULL; + } + + for (Block_Number_t UsedBlock = 0; UsedBlock < (ReqBlocks - 1); UsedBlock++) + Mem_SetBlockFlags((StartBlock + UsedBlock), (BLOCK_USED_MASK | BLOCK_LINKED_MASK)); + + Mem_SetBlockFlags((StartBlock + (ReqBlocks - 1)), BLOCK_USED_MASK); + + for (Handle_Number_t AllocEntry = 0; AllocEntry < NUM_HANDLES; AllocEntry++) + { + Mem_Handle_t CurrHdl = (Mem_Handle_t)&Mem_MemData.Mem_Handles[AllocEntry]; + + if (DEREF(CurrHdl, void*) == NULL) + { + DEREF(CurrHdl, void*) = &Mem_MemData.Mem_Heap[StartBlock * BLOCK_SIZE]; + return CurrHdl; + } + } + + return NULL; +} + +Mem_Handle_t Mem_Realloc(Mem_Handle_t CurrAllocHdl, const Alloc_Size_t Bytes) +{ + Mem_Free(CurrAllocHdl); + return Mem_Alloc(Bytes); +} + +Mem_Handle_t Mem_Calloc(const Alloc_Size_t Bytes) +{ + Mem_Handle_t AllocHdl = Mem_Alloc(Bytes); + + if (AllocHdl != NULL) + memset(DEREF(AllocHdl, void*), 0x00, Bytes); + + return AllocHdl; +} + +void Mem_Free(Mem_Handle_t CurrAllocHdl) +{ + char* MemBlockPtr = DEREF(CurrAllocHdl, char*); + Block_Number_t CurrBlock = ((uint16_t)(MemBlockPtr - Mem_MemData.Mem_Heap) / BLOCK_SIZE); + uint8_t CurrBlockFlags; + + if ((CurrAllocHdl == NULL) || (MemBlockPtr == NULL)) + return; + + do + { + CurrBlockFlags = Mem_GetBlockFlags(CurrBlock); + Mem_SetBlockFlags(CurrBlock, 0); + + CurrBlock++; + } + while (CurrBlockFlags & BLOCK_LINKED_MASK); + + DEREF(CurrAllocHdl, void*) = NULL; +} + +Block_Number_t Mem_TotalFreeBlocks(void) +{ + Block_Number_t FreeBlocks = 0; + + for (Block_Number_t CurrBlock = 0; CurrBlock < NUM_BLOCKS; CurrBlock++) + { + if (!(Mem_GetBlockFlags(CurrBlock) & BLOCK_USED_MASK)) + FreeBlocks++; + } + + return FreeBlocks; +} + +Handle_Number_t Mem_TotalFreeHandles(void) +{ + Handle_Number_t FreeHandles = 0; + + for (Handle_Number_t CurrHandle = 0; CurrHandle < NUM_HANDLES; CurrHandle++) + { + if (Mem_MemData.Mem_Handles[CurrHandle] == NULL) + FreeHandles++; + } + + return FreeHandles; +} diff --git a/LUFA/MemoryAllocator/DynAlloc.h b/LUFA/MemoryAllocator/DynAlloc.h new file mode 100644 index 0000000000..6fd743ea30 --- /dev/null +++ b/LUFA/MemoryAllocator/DynAlloc.h @@ -0,0 +1,182 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Dynamic, auto-defragmenting block memory allocator library. This library provides a convenient replacement for + * the standard avr-libc dynamic memory allocation routines. Memory is handed out in block chunks, to reduce the + * management memory overhead. + * + * Unlike the normal memory allocation routines, this library gives out handles to memory which must be dereferenced + * at the exact time of use, rather than handing back direct memory pointers. By using library managed handles + * instead of pointers, allocated memory blocks can be shifted around as needed transparently to defragment the + * memory as more blocks are requested. + * + * The memory heap is static, thus the total memory usage of the compiled application (as reported by the avr-size + * tool of the AVR-GCC toolchain) includes the dynamic memory heap. + * + * The constants NUM_BLOCKS, BLOCK_SIZE and NUM_HANDLES must be defined in the project makefile (and passed to the + * preprocessor via the -D GCC switch) for this library to compile. + * + * NUM_BLOCKS indicates the number of memory blocks in the memory psudoheap which can be chaned together and handed + * to the application via a memory handle. NUM_HANDLES is the maximum number of memory handles (pointing to one or + * more chained memory blocks) which can be handed out simultaneously before requring a handle (and its associated + * memory) to be freed. BLOCK_SIZE gives the number of bytes in each memory block. + */ + +#ifndef __DYN_ALLOC__ +#define __DYN_ALLOC__ + + /* Includes : */ + #include + #include + #include + + /* Preprocessor Checks: */ + #if (!defined(NUM_BLOCKS) || !defined(BLOCK_SIZE) || !defined(NUM_HANDLES)) + #error NUM_BLOCKS, BLOCK_SIZE and NUM_HANDLES must be defined before use via makefile. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Macro to dereference a given memory handle into the given type. The given type should be a pointer + * if the memory is to contain an array of items, or should be a standard type (such as a primative or + * structure) if the memory is to hold a single item of a single type. */ + #define DEREF(handle, type) (*(type*)handle) + + /** Constant, giving the total heap size in bytes. */ + #define ALLOCABLE_BYTES (1UL * NUM_BLOCKS * BLOCK_SIZE) + + /* Type Defines: */ + /** Memory handle type, used to store handles given by the library functions. */ + typedef const void** Mem_Handle_t; + + #if (ALLOCABLE_BYTES > 0xFFFF) || defined(__DOXYGEN__) + /** Type define for the size (in bytes) for an allocation for passing to the library functions. + * The exact type width varies depending on the value of ALLOCABLE_BYTES to ensure that a single + * allocation can request the entire heap if needed. + */ + typedef uint32_t Alloc_Size_t; + #elif (ALLOCABLE_BYTES > 0xFF) + typedef uint16_t Alloc_Size_t; + #else + typedef uint8_t Alloc_Size_t; + #endif + + #if (NUM_BLOCKS > 0xFFFF) || defined(__DOXYGEN__) + /** Type define for a block number in the heap. The exact type width varies depending on the + * value of NUM_BLOCKS to ensure that the type can store an index to any block in the block pool. + */ + typedef uint32_t Block_Number_t; + #elif (NUM_BLOCKS > 0xFF) + typedef uint16_t Block_Number_t; + #else + typedef uint8_t Block_Number_t; + #endif + + #if (NUM_HANDLES > 0xFFFF) || defined(__DOXYGEN__) + /** Type define for a handle number. The exact type width varies depending on the value of NUM_HANDLES + * to ensure that the type can store the index of any handle in the handle pool. + */ + typedef uint32_t Handle_Number_t; + #elif (NUM_HANDLES > 0xFF) + typedef uint16_t Handle_Number_t; + #else + typedef uint8_t Handle_Number_t; + #endif + + /* Function Prototypes: */ + /** Allocates a given number of blocks from the heap (calculated from the requested number of bytes) and + * returns a handle to the newly allocated memory. + * + * \param Bytes The number of bytes requested to be allocated from the heap + * + * \return NULL handle if the allocation fails, or handle to the allocated memory if the allocation succeeds + */ + Mem_Handle_t Mem_Alloc(const Alloc_Size_t Bytes); + + /** Allocates a given number of blocks from the heap (calculated from the requested number of bytes) and + * returns a handle to the newly allocated memory. Calloced memory is automatically cleared to all 0x00 + * values at the time of allocation. + * + * \param Bytes The number of pre-cleared bytes requested to be allocated from the heap + * + * \return NULL handle if the allocation fails, or handle to the allocated memory if the allocation succeeds + */ + Mem_Handle_t Mem_Calloc(const Alloc_Size_t Bytes); + + /** Deallocates a given memory handle, and attempts to allocates the given number of blocks from the heap + * (calculated from the requested number of bytes) immediately following the deallocation. The new memory + * may be located in the same area as the previous memory, but this is not guaranteed. + * + * \param CurrAllocHdl Handle to an already allocated section of memory in the heap to deallocate + * \param Bytes The number of bytes requested to be allocated from the heap following the + * deallocation + * + * \return NULL handle if the allocation fails, or handle to the allocated memory if the allocation succeeds + * + * \warning Even if the allocation fails, the deallocation will still occur. Care should be taken to ensure + * that the previously allocated memory is not used following an unsuccessful realloc(). + */ + Mem_Handle_t Mem_Realloc(Mem_Handle_t CurrAllocHdl, const Alloc_Size_t Bytes); + + /** Deallocates a given previously allocated section of memory from the heap. + * + * \param CurrAllocHdl Handle to a previously allocated section of memory in the heap + */ + void Mem_Free(Mem_Handle_t CurrAllocHdl); + + /** Returns the total number of unallocated blocks in the heap. + * + * \return Number of free blocks in the heap, as a Block_Number_t integer + */ + Block_Number_t Mem_TotalFreeBlocks(void); + + /** Returns the total number of unallocated handles in the handle pool. + * + * \return Number of free handles in the handle pool, as a Handle_Number_t integer + */ + Handle_Number_t Mem_TotalFreeHandles(void); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define BLOCK_USED_MASK (1 << 0) + #define BLOCK_LINKED_MASK (1 << 1) + + /* Function Prototypes: */ + #if defined(INCLUDE_FROM_DYNALLOC_C) + static uint8_t Mem_GetBlockFlags(const Block_Number_t BlockNum); + static void Mem_SetBlockFlags(const Block_Number_t BlockNum, const uint8_t Flags); + static void Mem_Defrag(void); + #endif + #endif + +#endif diff --git a/LUFA/MigrationInformation.txt b/LUFA/MigrationInformation.txt new file mode 100644 index 0000000000..1cdb55ae78 --- /dev/null +++ b/LUFA/MigrationInformation.txt @@ -0,0 +1,230 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \page Page_Migration Migrating from Older Versions + * + * Below is migration information for updating existing projects based on previous versions of the LUFA library + * to the next version released. It does not indicate all new additions to the library in each version change, only + * areas relevant to making older projects compatible with the API changes of each new release. + * + * \section Sec_MigrationXXXXXX Migrating from 090209 to XXXXXX + * + * + * \section Sec_Migration090209 Migrating from 081217 to 090209 + * + * Device Mode + * - The ENDPOINT_MAX_ENDPOINTS constant has been renamed to the more appropriate name of ENDPOINT_TOTAL_ENDPOINTS. + * - The USB_STREAM_TIMEOUT_MS stream timeout default period has been extended to 100ms. This can be overridden in the user + * makefile if desired to restore the previous 50ms timeout. + * + * Host Mode + * - The PIPE_MAX_ENDPOINTS constant has been renamed to the more appropriate name of PIPE_TOTAL_ENDPOINTS. + * - The USB_STREAM_TIMEOUT_MS stream timeout default period has been extended to 100ms. This can be overridden in the user + * makefile if desired to restore the previous 50ms timeout. + * - The USB_DeviceEnumerationFailed event now contains a second "SubErrorCode" parameter, giving the error code of the function + * which failed. + * - The HID_PARSE_Sucessful enum member constant has been corrected to HID_PARSE_Successful. + * + * Non-USB Library Components + * - The previous SPI_SendByte() functionality is now located in SPI_TransferByte(). SPI_SendByte() now discards the return byte + * for speed, to compliment the new SPI_ReceiveByte() function. If two-way SPI transfers are required, calls to SPI_SendByte() + * should be changed to SPI_TransferByte(). + * - The serial driver now sets the Tx line as an output explicitly, and enables the pullup of the Rx line. + * - The Serial_Init() and SerialStream_Init() functions now take a second DoubleSpeed parameter, which indicates if the USART + * should be initialized in double speed mode - useful in some circumstances for attaining baud rates not usually possible at + * the given AVR clock speed. + * + * Library Demos + * - Most library demos have been enhanced and/or had errors corrected. All users of all demos should upgrade their codebase to + * the latest demo versions. + * + * \section Sec_Migration171208 Migrating from V1.5.3 to 081217 + * + * All + * - The MyUSB project name has been changed to LUFA (Lightweight Framework for USB AVRs). All references to MyUSB, including macro names, + * have been changed to LUFA. + * + * Library Demos + * - The ReconfigureUSART() routine in the USBtoSerial demo was not being called after new line encoding + * parameters were set by the host. Projects built on the USBtoSerial code should update to the latest version. + * - The HID Parser now supports multiple report (on a single endpoint) HID devices. The MouseHostWithParser and + * KeyboardHostWithPaser demos use the updated API functions to function correctly on such devices. Projects + * built on either "WithParser" demo should update to the latest code. + * - The RNDIS demo TCP stack has been modified so that connections can be properly closed. It is still not + * recommended that the MyUSB RNDIS demo TCP/IP stack be used for anything other than demonstration purposes, + * as it is neither a full nor a standards compliant implementation. + * + * Non-USB Library Components + * - The Serial_IsCharRecieved() macro has been changed to the correct spelling of Serial_IsCharReceived() in Serial.h. + * + * Device Mode + * - The MANUAL_PLL_CONTROL compile time token has been removed, and replaced with a USB_OPT_MANUAL_PLL mask + * to be used in the Options parameter of the USB_Init() function. + * - Calling USB_Init() now forces a complete USB interface reset and enumeration, even if the USB interface is + * currently initialized. + * - Interrupts are now disabled when processing control requests, to avoid problems with interrupts causing the library + * or user request processing code to exceed the strict USB timing requirements on control transfers. + * - The USB Reset event now resets and disables all device endpoints. If user code depends on endpoints remaining configured + * after a Reset event, it should be altered to explicitly re-initialize all user endpoints. + * - The prototype for the GetDescriptor function has been changed, as the return value was redundant. The function now + * returns the size of the descriptor, rather than passing it back via a parameter, or returns NO_DESCRIPTOR if the specified + * descriptor does not exist. + * - The NO_DESCRIPTOR_STRING macro has been renamed NO_DESCRIPTOR, and is now also used as a possible return value for the + * GetDescriptor function. + * + * Host Mode + * - The MANUAL_PLL_CONTROL compile time token has been removed, and replaced with a USB_OPT_MANUAL_PLL mask + * to be used in the Options parameter of the USB_Init() function. + * - The HID report parser now supports multiple Report IDs. The HID report parser GetReportItemInfo() and + * SetReportItemInfo() routines now return a boolean, set if the requested report item was located in the + * current report. If sending a report to a multi-report device, the first byte of the report is automatically + * set to the report ID of the given report item. + * - Calling USB_Init() now forces a complete USB interface reset and enumeration, even if the USB interface is + * currently initialized. + * + * + * \section Sec_Migration152 Migrating from V1.5.2 to V1.5.3 + * + * Library Demos + * - Previously, all demos contained a serial number string descriptor, filled with all zeros. A serial number + * string is required in Mass Storage devices, or devices which are to retain settings when moved between + * ports on a machine. As people were not changing the serial number value, this was causing conflicts and so + * the serial number descriptor has been removed from all but the Mass Storage demo, which requires it. + * - The AudioOut and AudioIn demos did not previously silence their endpoints when the host has deactivated + * them. Projects built upon either demo should upgrade to the latest code. + * - The FEATURE_ENDPOINT macro has been renamed FEATURE_ENDPOINT_HALT, and is now correctly documented. + * - The MassStoreHost demo contained errors which caused it to lock up randomly on certain devices. Projects built + * on the MassStoreDemo code should update to the latest version. + * - The Interrupt type endpoint in the CDC based demos previously had a polling interval of 0x02, which caused + * problems on some Linux systems. This has been changed to 0xFF, projects built on the CDC demos should upgrade + * to the latest code. + * - The HID keyboard and mouse demos were not previously boot mode compatible. To enable boot mode support, projects + * built on the keyboard or mouse demos (or derivatives) should upgrade to the latest code. + * - The Mass Storage demo was not previously standards compliant. Projects built on the Mass Storage demo should + * upgrade to the latest code. + * - The USART was not being reconfigured after the host sent new encoding settings in the USBtoSerial demo. This was + * previously discovered and fixed, but the change was lost. Projects built on the USBtoSerial demo should update + * to the latest code. + * + * Device Mode + * - The endpoint non-control stream functions now have a default timeout of 50ms between packets in the stream. + * If this timeout is exceeded, the function returns the new ENDPOINT_RWSTREAM_ERROR_Timeout error value. The + * timeout value can be overridden by defining the USB_STREAM_TIMEOUT_MS in the project makefile to the desired + * timeout duration in ms. + * - Rather than returning fixed values, the flags indicating if the device has Remote Wakeup currently enabled + * and/or is self-powered are now accessed and set through the new USB_RemoteWakeupEnabled and + * USB_CurrentlySelfPowered macros. See the DevChapter9.h documentation for more details. + * - All endpoint stream functions now require an extra Callback function parameter. Existing code may be updated + * to either supply NO_STREAM_CALLBACK as the extra parameter, or disable stream callbacks altogether by pasing + * the token NO_STREAM_CALLBACKS to the compiler using the -D switch. + * + * Host Mode + * - The pipe non-control stream functions now have a default timeout of 50ms between packets in the stream. + * If this timeout is exceeded, the function returns the new PIPE_RWSTREAM_ERROR_Timeout error value. The + * timeout value can be overridden by defining the USB_STREAM_TIMEOUT_MS in the project makefile to the desired + * timeout duration in ms. + * - CollectionPath_t has been renamed to HID_CollectionPath_t to be more in line with the other HID parser structures. + * - All pipe stream functions now require an extra Callback function parameter. Existing code may be updated + * to either supply NO_STREAM_CALLBACK as the extra parameter, or disable stream callbacks altogether by pasing + * the token NO_STREAM_CALLBACKS to the compiler using the -D switch. + * + * + * \section Sec_Migration151 Migrating from V1.5.1 to V1.5.2 + * + * Library Demos + * - The RNDIS demo application has been updated so that it is functional on Linux under earlier implementations + * of the RNDIS specification, which had non-standard behaviour. Projects built upon the demo should upgrade + * to the latest code. + * - The DFU class bootloader has had several bugs corrected in this release. It is recommended that where + * possible any existing devices upgrade to the latest bootloader code. + * + * + * \section Sec_Migration150 Migrating from V1.5.0 to V1.5.1 + * + * Library Demos + * - The USBtoSerial demo was broken in the 1.5.0 release, due to incorrect register polling in place of the + * global "Transmitting" flag. The change has been reverted in this release. Projects built upon the demo + * should upgrade to the latest code. + * - The HID class demos did not implement the mandatory GetReport HID class request. Projects built upon the HID + * demos should upgrade to the latest code. + * - The HID class demos incorrectly reported themselves as boot-protocol enabled HID devices in their descriptors. + * Projects built upon the HID demos should upgrade to the latest code. + * - The MIDI device demo had incorrect AudioStreaming interface descriptors. Projects built upon the MIDI demo + * should upgrade to the latest code. + * - The AudioOut demo did not correctly tristate the speaker pins when USB was disconnected, wasting power. + * Projects built upon the AudioOut demo should upgrade to the latest code. + * + * + * \section Sec_Migration141 Migrating from V1.4.1 to V1.5.0 + * + * Library Demos + * - Previous versions of the library demos had incorrectly encoded BCD version numbers in the descriptors. To + * avoid such mistakes in the future, the VERSION_BCD macro has been added to StdDescriptors.h. Existing + * projects should at least manually correct the BCD version numbers, or preferably update the descriptors to + * encode the version number in BCD format using the new macro. + * - The mandatory GetReport class-specific request was accidentally ommitted from previous versions of the demos + * based on the Human Interface Device (HID) class. This has been corrected, and any user projects based on the + * HID demos should also be updated accordingly. + * - The CDC demos now correctly send an empty packet directly after a full packet, to end the transmission. + * Failure to do this on projects which always or frequently send full packets will cause buffering issues on + * the host OS. All CDC user projects are advised to update their transmission routines in the same manner as + * the library CDC demos. + * - The previous interrupt-driven Endpoint/Pipe demos did not properly save and restore the currently selected + * Endpoint/Pipe when the ISR fired. This has been corrected - user projects based on the interrupt driven + * demos should also update to properly save and restore the selected Endpoint/Pipe. + * + * Non-USB Library Components + * - The Atomic.h and ISRMacro.h header files in MyUSB/Common have been removed, as the library is now only + * compatible with avr-libc library versions newer than the time before the functionality of the deleted + * headers was available. + * + * Device Mode + * - The GetDescriptor function (see StdDescriptors.h) now has a new prototype, with altered parameter names and + * functions. Existing projects will need to update the GetDescriptor implementation to reflect the new API. + * The previously split Type and Index parameters are now passed as the original wValue parameter to the + * function, to make way for the USB specification wIndex parameter which is not the same as the + * previous Index parameter. + * - The USB_UnhandledControlPacket event (see Events.h) now has new parameter names, to be in line with the + * official USB specification. Existing code will need to be altered to use the new parameter names. + * - The USB_CreateEndpoints event (see Events.h) has been renamed to USB_ConfigurationChanged, which is more + * appropriate. It fires in an identical manner to the previously named event, thus the only change to be made + * is the event name itself in the user project. + * - The USB_Descriptor_Language_t structure no longer exists in StdDescriptors.h, as this was a + * psudo-descriptor modelled on the string descriptor. It is replaced by the true USB_Descriptor_String_t type + * descriptor as indicated in the USB specification, thus all device code must be updated accordingly. + * - The names of several Endpoint macros have been changed to be more consistant with the rest of the library, + * with no implementation changes. This means that existing code can be altered to use the new macro names + * with no other considerations required. See Endpoint.h for the new macro names. + * - The previous version of the MassStorage demo had an incorrect value in the SCSI_Request_Sense_Response_t + * strucuture named SenseData in SCSI.c which caused some problems with some hosts. User projects based on this + * demo should correct the structure value to maintain compatibility across multiple OS platforms. + * - By default, the descriptor structures use the official USB specification names for the elements. Previous + * versions of the library used non-standard (but more verbose) names, which are still usable in the current + * and future releases when the correct compile time option is enabled. See the StdDescriptors.h file + * documentation for more details. + * + * Host Mode + * - The USB_Host_Request_Header_t structure in HostChapter9.h (used for issuing control requests) has had its + * members renamed to the official USB specification names for requests. Existing code will need to be updated + * to use the new names. + * - The names of several Pipe macros have been changed to be more consistant with the rest of the library, + * with no implementation changes. This means that existing code can be altered to use the new macro names + * with no other considerations required. See Pipe.h for the new macro names. + * - By default, the descriptor structures use the official USB specification names for the elements. Previous + * versions of the library used non-standard (but more verbose) names, which are still usable in the current + * and future releases when the correct compile time option is enabled. See the StdDescriptors.h file + * documentation for more details. + * - The names of the macros in Host.h for controlling the SOF generation have been renamed, see the Host.h + * module documentation for the new macro names. + * + * Dual Role Mode + * - The OTG.h header file has been corrected so that the macros now perform their stated functions. Any existing + * projects using custom headers to fix the broken OTG header should now be altered to once again use the OTG + * header inside the library. + * - The USB_DeviceEnumerationComplete event (see Events.h) now also fires in Device mode, when the host has + * finished enumerating the device. Projects relying on the event only firing in Host mode should be updated + * so that the event action only ocurrs when the USB_Mode global is set to USB_MODE_HOST. + */ diff --git a/LUFA/Scheduler/Scheduler.c b/LUFA/Scheduler/Scheduler.c new file mode 100644 index 0000000000..ff8946a0d2 --- /dev/null +++ b/LUFA/Scheduler/Scheduler.c @@ -0,0 +1,95 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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. +*/ + +#include "Scheduler.h" + +volatile SchedulerDelayCounter_t Scheduler_TickCounter; +volatile uint8_t Scheduler_TotalTasks; + +bool Scheduler_HasDelayElapsed(const uint16_t Delay, SchedulerDelayCounter_t* const DelayCounter) +{ + SchedulerDelayCounter_t CurrentTickValue_LCL; + SchedulerDelayCounter_t DelayCounter_LCL; + + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + CurrentTickValue_LCL = Scheduler_TickCounter; + } + + DelayCounter_LCL = *DelayCounter; + + if (CurrentTickValue_LCL >= DelayCounter_LCL) + { + if ((CurrentTickValue_LCL - DelayCounter_LCL) >= Delay) + { + *DelayCounter = CurrentTickValue_LCL; + return true; + } + } + else + { + if (((MAX_DELAYCTR_COUNT - DelayCounter_LCL) + CurrentTickValue_LCL) >= Delay) + { + *DelayCounter = CurrentTickValue_LCL; + return true; + } + } + + return false; +} + +void Scheduler_SetTaskMode(const TaskPtr_t Task, const bool TaskStatus) +{ + TaskEntry_t* CurrTask = &Scheduler_TaskList[0]; + + while (CurrTask != &Scheduler_TaskList[Scheduler_TotalTasks]) + { + if (CurrTask->Task == Task) + { + CurrTask->TaskStatus = TaskStatus; + break; + } + + CurrTask++; + } +} + +void Scheduler_SetGroupTaskMode(const uint8_t GroupID, const bool TaskStatus) +{ + TaskEntry_t* CurrTask = &Scheduler_TaskList[0]; + + while (CurrTask != &Scheduler_TaskList[Scheduler_TotalTasks]) + { + if (CurrTask->GroupID == GroupID) + CurrTask->TaskStatus = TaskStatus; + + CurrTask++; + } +} diff --git a/LUFA/Scheduler/Scheduler.h b/LUFA/Scheduler/Scheduler.h new file mode 100644 index 0000000000..39f94ef80a --- /dev/null +++ b/LUFA/Scheduler/Scheduler.h @@ -0,0 +1,262 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Simple round-robbin cooperative scheduler for use in basic projects where non realtime tasks need + * to be executed. Each task is executed in sequence, and can be enabled or disabled individually or as a group. + * + * For a task to yield it must return, thus each task should have persistant data marked with the static attribute. + * + * Usage Example: + * \code + * #include + * + * TASK(MyTask1); + * TASK(MyTask2); + * + * TASK_LIST + * { + * { Task: MyTask1, TaskStatus: TASK_RUN, GroupID: 1 }, + * { Task: MyTask2, TaskStatus: TASK_RUN, GroupID: 1 }, + * } + * + * int main(void) + * { + * Scheduler_Start(); + * } + * + * TASK(MyTask1) + * { + * // Implementation Here + * } + * + * TASK(MyTask2) + * { + * // Implementation Here + * } + * \endcode + */ + +#ifndef __SCHEDULER_H__ +#define __SCHEDULER_H__ + + /* Includes: */ + #include + #include + + #include + + #include "../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Creates a new scheduler task body or prototype. Should be used in the form: + * \code + * TASK(TaskName); // Prototype + * + * TASK(TaskName) + * { + * // Task body + * } + * \endcode + */ + #define TASK(name) void name (void) + + /** Defines a task list array, containing one or more task entries of the type TaskEntry_t. Each task list + * should be encased in curly braces and ended with a comma. + * + * Usage Example: + * \code + * TASK_LIST + * { + * { Task: MyTask1, TaskStatus: TASK_RUN, GroupID: 1 }, + * // More task entries here + * } + * \endcode + */ + #define TASK_LIST extern TaskEntry_t Scheduler_TaskList[]; TaskEntry_t Scheduler_TaskList[] = + + /** Constant, giving the maximum delay in scheduler ticks which can be stored in a variable of type + * SchedulerDelayCounter_t. + */ + #define TASK_MAX_DELAY (MAX_DELAYCTR_COUNT - 1) + + /** Task status mode constant, for passing to Scheduler_SetTaskMode() or Scheduler_SetGroupTaskMode(). */ + #define TASK_RUN true + + /** Task status mode constant, for passing to Scheduler_SetTaskMode() or Scheduler_SetGroupTaskMode(). */ + #define TASK_STOP false + + /** Starts the scheduler in its infinite loop, executing running tasks. This should be placed at the end + * of the user application's main() function, as it can never return to the calling function. + */ + #define Scheduler_Start() Scheduler_GoSchedule(TOTAL_TASKS); + + /** Initializes the scheduler so that the scheduler functions can be called before the scheduler itself + * is started. This must be exeucted before any scheduler function calls other than Scheduler_Start(), + * and can be ommitted if no such functions could be called before the scheduler is started. + */ + #define Scheduler_Init() Scheduler_InitScheduler(TOTAL_TASKS); + + /* Type Defines: */ + /** Type define for a pointer to a scheduler task. */ + typedef void (*TaskPtr_t)(void); + + /** Type define for a variable which can hold a tick delay value for the scheduler up to the maximum delay + * possible. + */ + typedef uint16_t SchedulerDelayCounter_t; + + /** Structure for holding a single task's information in the scheduler task list. */ + typedef struct + { + TaskPtr_t Task; /**< Pointer to the task to execute. */ + bool TaskStatus; /**< Status of the task (either TASK_RUN or TASK_STOP). */ + uint8_t GroupID; /**< Group ID of the task so that its status can be changed as a group. */ + } TaskEntry_t; + + /* Global Variables: */ + /** Task entry list, containing the scheduler tasks, task statuses and group IDs. Each entry is of type + * TaskEntry_t and can be manipulated as desired, although it is preferential that the proper Scheduler + * functions should be used instead of direct manipulation. + */ + extern TaskEntry_t Scheduler_TaskList[]; + + /** Contains the total number of tasks in the task list, irrespective of if the task's status is set to + * TASK_RUN or TASK_STOP. + * + * \note This value should be treated as read-only, and never altered in user-code. + */ + extern volatile uint8_t Scheduler_TotalTasks; + + /** Contains the current scheduler tick count, for use with the delay functions. If the delay functions + * are used in the user code, this should be incremented each tick period so that the delays can be + * calculated. + */ + extern volatile SchedulerDelayCounter_t Scheduler_TickCounter; + + /* Inline Functions: */ + /** Resets the delay counter value to the current tick count. This should be called to reset the period + * for a delay in a task which is dependant on the current tick value. + * + * \param DelayCounter Counter which is storing the starting tick count for a given delay. + */ + static inline void Scheduler_ResetDelay(SchedulerDelayCounter_t* const DelayCounter) + ATTR_NON_NULL_PTR_ARG(1); + static inline void Scheduler_ResetDelay(SchedulerDelayCounter_t* const DelayCounter) + { + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + *DelayCounter = Scheduler_TickCounter; + } + } + + /* Function Prototypes: */ + /** Determines if the given tick delay has elapsed, based on the given . + * + * \param Delay The delay to test for, measured in ticks + * \param DelayCounter The counter which is storing the starting tick value for the delay + * + * \return Boolean true if the delay has elapsed, false otherwise + * + * Usage Example: + * \code + * static SchedulerDelayCounter_t DelayCounter = 10000; // Force immediate run on startup + * + * // Task runs every 10000 ticks, 10 seconds for this demo + * if (Scheduler_HasDelayElapsed(10000, &DelayCounter)) + * { + * // Code to execute after delay interval elapsed here + * } + * \endcode + */ + bool Scheduler_HasDelayElapsed(const uint16_t Delay, + SchedulerDelayCounter_t* const DelayCounter) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(2); + + /** Sets the task mode for a given task. + * + * \param Task Name of the task whose status is to be changed + * \param TaskStatus New task status for the task (TASK_RUN or TASK_STOP) + */ + void Scheduler_SetTaskMode(const TaskPtr_t Task, const bool TaskStatus); + + /** Sets the task mode for a given task group ID, allowing for an entire group of tasks to have their + * statuses changed at once. + * + * \param GroupID Value of the task group ID whose status is to be changed + * \param TaskStatus New task status for tasks in the specified group (TASK_RUN or TASK_STOP) + */ + void Scheduler_SetGroupTaskMode(const uint8_t GroupID, const bool TaskStatus); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define TOTAL_TASKS (sizeof(Scheduler_TaskList) / sizeof(TaskEntry_t)) + #define MAX_DELAYCTR_COUNT 0xFFFF + + /* Inline Functions: */ + static inline void Scheduler_InitScheduler(const uint8_t TotalTasks) + { + Scheduler_TotalTasks = TotalTasks; + } + + static inline void Scheduler_GoSchedule(const uint8_t TotalTasks) ATTR_NO_RETURN; + static inline void Scheduler_GoSchedule(const uint8_t TotalTasks) + { + Scheduler_InitScheduler(TotalTasks); + + for (;;) + { + TaskEntry_t* CurrTask = &Scheduler_TaskList[0]; + + while (CurrTask != &Scheduler_TaskList[TotalTasks]) + { + if (CurrTask->TaskStatus == TASK_RUN) + CurrTask->Task(); + + CurrTask++; + } + } + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/SchedulerOverview.txt b/LUFA/SchedulerOverview.txt new file mode 100644 index 0000000000..0a4f49282b --- /dev/null +++ b/LUFA/SchedulerOverview.txt @@ -0,0 +1,31 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \page Page_SchedulerOverview LUFA Scheduler Overview + * + * The LUFA library comes with a small, basic round-robbin scheduler which allows for small "tasks" to be executed + * continuously in sequence, and enabled/disabled at runtime. Unlike a conventional, complex RTOS scheduler, the + * LUFA scheduler is very simple in design and operation and is essentially a loop conditionally executing a series + * of functions. + * + * Each LUFA scheduler task should be written similar to an ISR; it should execute quickly (so that no one task + * hogs the processor, preventing another from running before some sort of timeout is exceeded). Unlike normal RTOS + * tasks, each LUFA scheduler task is a regular function, and thus must be designed to be called, and designed to + * return to the calling scheduler function repeatedly. Data which must be preserved between task calls should be + * declared as global or (prefferably) as a static local variable inside the task. + * + * The scheduler consists of a task list, listing all the tasks which can be executed by the scheduler. Once started, + * each task is then called one after another, unless the task is stopped by another running task or interrupt. + * + * + * If desired, the LUFA scheduler does not need to be used in a LUFA powered application. A more conventional + * approach to application design can be used, or a proper scheduling RTOS inserted in the place of the LUFA scheduler. + * In the case of the former the USB task must be run manually repeatedly to maintain USB communications, and in the + * case of the latter a proper RTOS task must be set up to do the same. + * + * + * For more information on the LUFA scheduler, see the Scheduler.h file documentation. + */ diff --git a/LUFA/VIDAndPIDValues.txt b/LUFA/VIDAndPIDValues.txt new file mode 100644 index 0000000000..429bc2bbfd --- /dev/null +++ b/LUFA/VIDAndPIDValues.txt @@ -0,0 +1,224 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \page Page_VIDPID VID and PID values + * + * The LUFA library uses VID/PID combinations generously donated by Atmel. The following VID/PID combinations + * are used within the LUFA demos, and thus may be re-used by derivations of each demo. Free PID values may be + * used by future LUFA demo projects. + * + * These VID/PID values should not be used in commercial designs under any circumstances. Private projects may + * use the following values freely, but must accept any collisions due to other LUFA derived private projects + * sharing identical values. It is suggested that private projects using interfaces compatible with existing + * demos share the save VID/PID value. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
+ * VID + * + * PID + * + * Usage + *
+ * 0x03EB + * + * 0x2040 + * + * Test Application + *
+ * 0x03EB + * + * 0x2041 + * + * Mouse Demo Application (and derivatives) + *
+ * 0x03EB + * + * 0x2042 + * + * Keyboard Demo Application (and derivatives) + *
+ * 0x03EB + * + * 0x2043 + * + * Joystick Demo Application + *
+ * 0x03EB + * + * 0x2044 + * + * CDC Demo Application + *
+ * 0x03EB + * + * 0x2045 + * + * Mass Storage Demo Application + *
+ * 0x03EB + * + * 0x2046 + * + * Audio Output Demo Application + *
+ * 0x03EB + * + * 0x2047 + * + * Audio Input Demo Application + *
+ * 0x03EB + * + * 0x2048 + * + * MIDI Demo Application + *
+ * 0x03EB + * + * 0x2049 + * + * MagStripe Project + *
+ * 0x03EB + * + * 0x204A + * + * CDC Bootloader + *
+ * 0x03EB + * + * 0x204B + * + * USB to Serial Demo Application + *
+ * 0x03EB + * + * 0x204C + * + * RNDIS Demo Application + *
+ * 0x03EB + * + * 0x204D + * + * Keyboard and Mouse Combination Demo Application + *
+ * 0x03EB + * + * 0x204E + * + * Dual CDC Demo Application + *
+ * 0x03EB + * + * 0x204F + * + * AVRISP Programmer Project + *
+ */ diff --git a/LUFA/Version.h b/LUFA/Version.h new file mode 100644 index 0000000000..f36c40a92d --- /dev/null +++ b/LUFA/Version.h @@ -0,0 +1,49 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 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 + * + * Version constants for informational purposes and version-specific macro creation. This header file contains the + * current LUFA version number in several forms, for use in the user-application (for example, for printing out + * whilst debugging, or for testing for version compatibility). + */ + +#ifndef __LUFA_VERSION_H__ +#define __LUFA_VERSION_H__ + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Indicates the version number of the library, as an integer. */ + #define LUFA_VERSION_INTEGER 000000 + + /** Indicates the version number of the library, as a string. */ + #define LUFA_VERSION_STRING "000000" + +#endif diff --git a/LUFA/WritingBoardDrivers.txt b/LUFA/WritingBoardDrivers.txt new file mode 100644 index 0000000000..0d0e74d049 --- /dev/null +++ b/LUFA/WritingBoardDrivers.txt @@ -0,0 +1,26 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \page Page_WritingBoardDrivers Writing LUFA Board Drivers + * + * LUFA ships with several basic pre-made board drivers, to control hardware present on the supported board + * hardware - such as Dataflash ICs, LEDs, Joysticks, or other hardware peripherals. When compiling an application + * which makes use of one or more board drivers located in LUFA/Drivers/Board, you must also indicate what board + * hardware you are using in your project makefile. This is done by defining the BOARD macro using the -D switch + * passed to the compiler, with a constant of BOARD_{Name}. For example -DBOARD=BOARD_USBKEY instructs the + * compiler to use the USBKEY board hardware drivers. + * + * If your application does not use *any* board level drivers, you can ommit the definition of the BOARD macro. + * However, some users may wish to write their own custom board hardware drivers which are to remain compatible + * with the LUFA hardware API. To do this, the BOARD macro should be defined to the value BOARD_USER. This indicates + * that the board level drivers should be located in a folder named "Board" located inside the application's folder. + * + * When used, the driver stub files located in the DriverStubs folder should be copied to the user Board directory, + * and fleshed out to include the values and code needed to control the custom board hardware. Once done, the existing + * LUFA board level APIs (accessed in the regular LUFA/Drivers/Board/ folder) will redirect to the user board drivers, + * maintaining code compatibility and allowing for a different board to be selected through the project makefile with + * no code changes. + */ diff --git a/LUFA/makefile b/LUFA/makefile new file mode 100644 index 0000000000..4020936f57 --- /dev/null +++ b/LUFA/makefile @@ -0,0 +1,42 @@ +# +# LUFA Library +# Copyright (C) Dean Camera, 2009. +# +# dean [at] fourwalledcubicle [dot] com +# www.fourwalledcubicle.com +# + +# Makefile for the LUFA library itself. + +LUFA_SRC_FILES = ./Drivers/USB/LowLevel/LowLevel.c \ + ./Drivers/USB/LowLevel/Endpoint.c \ + ./Drivers/USB/LowLevel/Pipe.c \ + ./Drivers/USB/LowLevel/DevChapter9.c \ + ./Drivers/USB/LowLevel/HostChapter9.c \ + ./Drivers/USB/LowLevel/Host.c \ + ./Drivers/USB/HighLevel/USBTask.c \ + ./Drivers/USB/HighLevel/USBInterrupt.c \ + ./Drivers/USB/HighLevel/Events.c \ + ./Drivers/USB/HighLevel/StdDescriptors.c \ + ./Drivers/USB/Class/HIDParser.c \ + ./Drivers/USB/Class/ConfigDescriptor.c \ + ./Scheduler/Scheduler.c \ + ./MemoryAllocator/DynAlloc.c \ + ./Drivers/Board/Temperature.c \ + ./Drivers/AT90USBXXX/Serial.c \ + ./Drivers/AT90USBXXX/Serial_Stream.c \ + +all: + +clean: + rm -f $(LUFA_SRC_FILES:%.c=%.o) + +clean_list: + +doxygen: + @echo Generating Library Documentation... + @doxygen Doxygen.conf + @echo Documentation Generation Complete. + +clean_doxygen: + rm -rf Documentation