diff --git a/branches/LUFA-IAR-Port/Bootloaders/CDC/BootloaderAPITable.S b/branches/LUFA-IAR-Port/Bootloaders/CDC/BootloaderAPITable.S index a8e38861d..060a7abea 100644 --- a/branches/LUFA-IAR-Port/Bootloaders/CDC/BootloaderAPITable.S +++ b/branches/LUFA-IAR-Port/Bootloaders/CDC/BootloaderAPITable.S @@ -1,6 +1,6 @@ /* LUFA Library - Copyright (C) Dean Camera, 2011. + Copyright (C) Dean Camera, 2012. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org @@ -28,41 +28,44 @@ this software. */ -; Bootloader API Jump Table -.section .apitable, "ax" - ; Trampolines to actual API implementations if the target address is outside the ; range of a rjmp instruction (can happen with large bootloader sections) -.org 0 -BootloaderAPI_ErasePage_Trampoline: - jmp BootloaderAPI_ErasePage -BootloaderAPI_WritePage_Trampoline: - jmp BootloaderAPI_WritePage -BootloaderAPI_FillWord_Trampoline: - jmp BootloaderAPI_FillWord -BootloaderAPI_ReadSignature_Trampoline: - jmp BootloaderAPI_ReadSignature -BootloaderAPI_ReadFuse_Trampoline: - jmp BootloaderAPI_ReadFuse -BootloaderAPI_ReadLock_Trampoline: - jmp BootloaderAPI_ReadLock -BootloaderAPI_WriteLock_Trampoline: - jmp BootloaderAPI_WriteLock -BootloaderAPU_UNUSED1: - ret -BootloaderAPU_UNUSED2: - ret -BootloaderAPU_UNUSED3: - ret -BootloaderAPU_UNUSED4: - ret -BootloaderAPU_UNUSED5: - ret +.section .apitable_trampolines, "ax" +.global BootloaderAPI_Trampolines +BootloaderAPI_Trampolines: + + BootloaderAPI_ErasePage_Trampoline: + jmp BootloaderAPI_ErasePage + BootloaderAPI_WritePage_Trampoline: + jmp BootloaderAPI_WritePage + BootloaderAPI_FillWord_Trampoline: + jmp BootloaderAPI_FillWord + BootloaderAPI_ReadSignature_Trampoline: + jmp BootloaderAPI_ReadSignature + BootloaderAPI_ReadFuse_Trampoline: + jmp BootloaderAPI_ReadFuse + BootloaderAPI_ReadLock_Trampoline: + jmp BootloaderAPI_ReadLock + BootloaderAPI_WriteLock_Trampoline: + jmp BootloaderAPI_WriteLock + BootloaderAPU_UNUSED1: + ret + BootloaderAPU_UNUSED2: + ret + BootloaderAPU_UNUSED3: + ret + BootloaderAPU_UNUSED4: + ret + BootloaderAPU_UNUSED5: + ret + + ; API function jump table -.org (96 - 32) +.section .apitable_jumptable, "ax" .global BootloaderAPI_JumpTable BootloaderAPI_JumpTable: + rjmp BootloaderAPI_ErasePage_Trampoline rjmp BootloaderAPI_WritePage_Trampoline rjmp BootloaderAPI_FillWord_Trampoline @@ -76,10 +79,13 @@ BootloaderAPI_JumpTable: rjmp BootloaderAPU_UNUSED4 ; UNUSED ENTRY 4 rjmp BootloaderAPU_UNUSED5 ; UNUSED ENTRY 5 + + ; Bootloader table signatures and information -.org (96 - 8) -BootloaderAPI_Signatures: +.section .apitable_signatures, "ax" .global BootloaderAPI_Signatures +BootloaderAPI_Signatures: + .long BOOT_START_ADDR ; Start address of the bootloader - .word 0xCDC1 ; Signature for the CDC class bootloader, V1 + .word 0xDFB1 ; Signature for the DFU class bootloader, V1 .word 0xDCFB ; Signature for a LUFA class bootloader diff --git a/branches/LUFA-IAR-Port/Bootloaders/CDC/makefile b/branches/LUFA-IAR-Port/Bootloaders/CDC/makefile index 68bf4c63f..2c21fb69f 100644 --- a/branches/LUFA-IAR-Port/Bootloaders/CDC/makefile +++ b/branches/LUFA-IAR-Port/Bootloaders/CDC/makefile @@ -15,10 +15,15 @@ FLASH_SIZE_KB := 128 BOOT_SECTION_SIZE_KB := 8 -# Bootloader address calculations (requires the "bc" unix utility) - do -# not modify these calculations, but rather modify the depedant values above. +# Bootloader address calculations (requires the "bc" unix utility) and +# API section start directives - do not modify these macros, but rather +# modify the depedant values above. BOOT_START := 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc) -BOOT_API_TABLESTART := 0x$(shell echo "obase=16; (($(FLASH_SIZE_KB) * 1024) - 96)" | bc) +BOOT_SEC_OFFSET = 0x$(shell echo "obase=16; (($(FLASH_SIZE_KB) * 1024) - $(strip $(1)))" | bc) +BOOT_SECTION_LD_FLAG = -Wl,--section-start=.apitable_$(strip $(1))=$(call BOOT_SEC_OFFSET, $(3)) -Wl,--undefined=BootloaderAPI_$(strip $(2)) +BOOT_API_LD_FLAGS := $(call BOOT_SECTION_LD_FLAG, trampolines, Trampolines, (48 + 32 + 8)) +BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, jumptable, JumpTable, (32 + 8)) +BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, signatures, Signatures, 8) MCU = at90usb1287 ARCH = AVR8 @@ -30,7 +35,7 @@ TARGET = BootloaderCDC SRC = $(TARGET).c Descriptors.c BootloaderAPI.c BootloaderAPITable.S $(LUFA_SRC_USB) LUFA_PATH = ../../LUFA/ CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ -DBOOT_START_ADDR=$(BOOT_START) -LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START) -Wl,--section-start=.apitable=$(BOOT_API_TABLESTART) -Wl,--undefined=BootloaderAPI_JumpTable +LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START) $(BOOT_API_LD_FLAGS) # Default target all: diff --git a/branches/LUFA-IAR-Port/Bootloaders/DFU/BootloaderAPITable.S b/branches/LUFA-IAR-Port/Bootloaders/DFU/BootloaderAPITable.S index 18ae390fc..9d1e2fc0e 100644 --- a/branches/LUFA-IAR-Port/Bootloaders/DFU/BootloaderAPITable.S +++ b/branches/LUFA-IAR-Port/Bootloaders/DFU/BootloaderAPITable.S @@ -7,7 +7,7 @@ */ /* - Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -28,41 +28,44 @@ this software. */ -; Bootloader API Jump Table -.section .apitable, "ax" - ; Trampolines to actual API implementations if the target address is outside the ; range of a rjmp instruction (can happen with large bootloader sections) -.org 0 -BootloaderAPI_ErasePage_Trampoline: - jmp BootloaderAPI_ErasePage -BootloaderAPI_WritePage_Trampoline: - jmp BootloaderAPI_WritePage -BootloaderAPI_FillWord_Trampoline: - jmp BootloaderAPI_FillWord -BootloaderAPI_ReadSignature_Trampoline: - jmp BootloaderAPI_ReadSignature -BootloaderAPI_ReadFuse_Trampoline: - jmp BootloaderAPI_ReadFuse -BootloaderAPI_ReadLock_Trampoline: - jmp BootloaderAPI_ReadLock -BootloaderAPI_WriteLock_Trampoline: - jmp BootloaderAPI_WriteLock -BootloaderAPU_UNUSED1: - ret -BootloaderAPU_UNUSED2: - ret -BootloaderAPU_UNUSED3: - ret -BootloaderAPU_UNUSED4: - ret -BootloaderAPU_UNUSED5: - ret +.section .apitable_trampolines, "ax" +.global BootloaderAPI_Trampolines +BootloaderAPI_Trampolines: + + BootloaderAPI_ErasePage_Trampoline: + jmp BootloaderAPI_ErasePage + BootloaderAPI_WritePage_Trampoline: + jmp BootloaderAPI_WritePage + BootloaderAPI_FillWord_Trampoline: + jmp BootloaderAPI_FillWord + BootloaderAPI_ReadSignature_Trampoline: + jmp BootloaderAPI_ReadSignature + BootloaderAPI_ReadFuse_Trampoline: + jmp BootloaderAPI_ReadFuse + BootloaderAPI_ReadLock_Trampoline: + jmp BootloaderAPI_ReadLock + BootloaderAPI_WriteLock_Trampoline: + jmp BootloaderAPI_WriteLock + BootloaderAPU_UNUSED1: + ret + BootloaderAPU_UNUSED2: + ret + BootloaderAPU_UNUSED3: + ret + BootloaderAPU_UNUSED4: + ret + BootloaderAPU_UNUSED5: + ret + + ; API function jump table -.org (96 - 32) +.section .apitable_jumptable, "ax" .global BootloaderAPI_JumpTable BootloaderAPI_JumpTable: + rjmp BootloaderAPI_ErasePage_Trampoline rjmp BootloaderAPI_WritePage_Trampoline rjmp BootloaderAPI_FillWord_Trampoline @@ -76,10 +79,13 @@ BootloaderAPI_JumpTable: rjmp BootloaderAPU_UNUSED4 ; UNUSED ENTRY 4 rjmp BootloaderAPU_UNUSED5 ; UNUSED ENTRY 5 + + ; Bootloader table signatures and information -.org (96 - 8) -BootloaderAPI_Signatures: +.section .apitable_signatures, "ax" .global BootloaderAPI_Signatures +BootloaderAPI_Signatures: + .long BOOT_START_ADDR ; Start address of the bootloader .word 0xDFB1 ; Signature for the DFU class bootloader, V1 .word 0xDCFB ; Signature for a LUFA class bootloader diff --git a/branches/LUFA-IAR-Port/Bootloaders/DFU/Descriptors.c b/branches/LUFA-IAR-Port/Bootloaders/DFU/Descriptors.c index ff33b6b64..3a1a2e2b3 100644 --- a/branches/LUFA-IAR-Port/Bootloaders/DFU/Descriptors.c +++ b/branches/LUFA-IAR-Port/Bootloaders/DFU/Descriptors.c @@ -57,8 +57,8 @@ const USB_Descriptor_Device_t DeviceDescriptor = .ProductID = PRODUCT_ID_CODE, .ReleaseNumber = VERSION_BCD(00.00), - .ManufacturerStrIndex = NO_DESCRIPTOR, - .ProductStrIndex = 0x01, + .ManufacturerStrIndex = 0x01, + .ProductStrIndex = 0x02, .SerialNumStrIndex = NO_DESCRIPTOR, .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS @@ -126,6 +126,17 @@ const USB_Descriptor_String_t LanguageString = .UnicodeString = {LANGUAGE_ID_ENG} }; +/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable + * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device + * Descriptor. + */ +const USB_Descriptor_String_t PROGMEM ManufacturerString = +{ + .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, + + .UnicodeString = L"Dean Camera" +}; + /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * Descriptor. @@ -169,7 +180,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Address = &LanguageString; Size = LanguageString.Header.Size; } - else + else if (DescriptorNumber == 0x01) + { + Address = &ManufacturerString; + Size = ManufacturerString.Header.Size; + } + else if (DescriptorNumber == 0x02) { Address = &ProductString; Size = ProductString.Header.Size; diff --git a/branches/LUFA-IAR-Port/Bootloaders/DFU/makefile b/branches/LUFA-IAR-Port/Bootloaders/DFU/makefile index 75b36ec63..3ee61fc8d 100644 --- a/branches/LUFA-IAR-Port/Bootloaders/DFU/makefile +++ b/branches/LUFA-IAR-Port/Bootloaders/DFU/makefile @@ -15,10 +15,15 @@ FLASH_SIZE_KB := 128 BOOT_SECTION_SIZE_KB := 8 -# Bootloader address calculations (requires the "bc" unix utility) - do -# not modify these calculations, but rather modify the depedant values above. +# Bootloader address calculations (requires the "bc" unix utility) and +# API section start directives - do not modify these macros, but rather +# modify the depedant values above. BOOT_START := 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc) -BOOT_API_TABLESTART := 0x$(shell echo "obase=16; (($(FLASH_SIZE_KB) * 1024) - 96)" | bc) +BOOT_SEC_OFFSET = 0x$(shell echo "obase=16; (($(FLASH_SIZE_KB) * 1024) - $(strip $(1)))" | bc) +BOOT_SECTION_LD_FLAG = -Wl,--section-start=.apitable_$(strip $(1))=$(call BOOT_SEC_OFFSET, $(3)) -Wl,--undefined=BootloaderAPI_$(strip $(2)) +BOOT_API_LD_FLAGS := $(call BOOT_SECTION_LD_FLAG, trampolines, Trampolines, (48 + 32 + 8)) +BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, jumptable, JumpTable, (32 + 8)) +BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, signatures, Signatures, 8) MCU = at90usb1287 ARCH = AVR8 @@ -30,7 +35,7 @@ TARGET = BootloaderDFU SRC = $(TARGET).c Descriptors.c BootloaderAPI.c BootloaderAPITable.S $(LUFA_SRC_USB) LUFA_PATH = ../../LUFA/ CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ -DBOOT_START_ADDR=$(BOOT_START) -LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START) -Wl,--section-start=.apitable=$(BOOT_API_TABLESTART) -Wl,--undefined=BootloaderAPI_JumpTable +LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START) $(BOOT_API_LD_FLAGS) # Default target all: diff --git a/branches/LUFA-IAR-Port/BuildTests/BootloaderTest/makefile b/branches/LUFA-IAR-Port/BuildTests/BootloaderTest/makefile index baee18e86..1294ba084 100644 --- a/branches/LUFA-IAR-Port/BuildTests/BootloaderTest/makefile +++ b/branches/LUFA-IAR-Port/BuildTests/BootloaderTest/makefile @@ -41,7 +41,7 @@ testbootloaders: build_flashsize=`echo $$build_cfg | cut -d':' -f4`; \ build_bootsize=`echo $$build_cfg | cut -d':' -f5`; \ \ - printf "Found bootloader configuration for bootloader '%s' (FLASH: %3s KB | BOOT: %3s KB | MCU: %12s / %4s)\n" $$build_bootloader $$build_flashsize $$build_bootsize $$build_mcu $$build_arch; \ + printf "Found '%s' bootloader configuration (FLASH: %3s KB | BOOT: %3s KB | MCU: %12s / %4s)\n" $$build_bootloader $$build_flashsize $$build_bootsize $$build_mcu $$build_arch; \ \ printf "\t@echo Building bootloader %s - %s - FLASH: %s KB, BOOT: %s KB\n" $$build_bootloader $$build_mcu $$build_flashsize $$build_bootsize >> BuildMakefile; \ printf "\t$(MAKE) -s -C $(patsubst %/,%,$(LUFA_PATH))/../Bootloaders/%s/ clean elf ARCH=%s MCU=%s BOARD=%s FLASH_SIZE_KB=%s BOOT_SECTION_SIZE_KB=%s\n\n" $$build_bootloader $$build_arch $$build_mcu $$build_board $$build_flashsize $$build_bootsize >> BuildMakefile; \ diff --git a/branches/LUFA-IAR-Port/BuildTests/ModuleTest/makefile b/branches/LUFA-IAR-Port/BuildTests/ModuleTest/makefile index 8a20d0452..b997b3513 100644 --- a/branches/LUFA-IAR-Port/BuildTests/ModuleTest/makefile +++ b/branches/LUFA-IAR-Port/BuildTests/ModuleTest/makefile @@ -39,12 +39,15 @@ end: @echo %.avr8: + @echo Building ModuleTest for ARCH=AVR8 MCU=$(@:%.avr8=%)... $(MAKE) -s -f makefile.test clean elf ARCH=AVR8 MCU=$(@:%.avr8=%) %.xmega: + @echo Building ModuleTest for ARCH=XMEGA MCU=$(@:%.xmega=%)... $(MAKE) -s -f makefile.test clean elf ARCH=XMEGA MCU=$(@:%.xmega=%) %.uc3: + @echo Building ModuleTest for ARCH=UC3 MCU=$(@:%.uc3=%)... $(MAKE) -s -f makefile.test clean elf ARCH=UC3 MCU=$(@:%.uc3=%) clean: diff --git a/branches/LUFA-IAR-Port/BuildTests/SingleUSBModeTest/makefile b/branches/LUFA-IAR-Port/BuildTests/SingleUSBModeTest/makefile index 6b5af1eb2..d5fd3f06e 100644 --- a/branches/LUFA-IAR-Port/BuildTests/SingleUSBModeTest/makefile +++ b/branches/LUFA-IAR-Port/BuildTests/SingleUSBModeTest/makefile @@ -25,12 +25,19 @@ end: @echo compile: + @echo Building SingleUSBModeTest for ARCH=AVR8 in device only mode... $(MAKE) -s -f makefile.test clean elf ARCH=AVR8 MCU=at90usb1287 CC_FLAGS='-D USB_DEVICE_ONLY' + + @echo Building SingleUSBModeTest for ARCH=AVR8 in host only mode... $(MAKE) -s -f makefile.test clean elf ARCH=AVR8 MCU=at90usb1287 CC_FLAGS='-D USB_HOST_ONLY' + @echo Building SingleUSBModeTest for ARCH=XMEGA in device only mode... $(MAKE) -s -f makefile.test clean elf ARCH=XMEGA MCU=atxmega128a1u CC_FLAGS='-D USB_DEVICE_ONLY' + @echo Building SingleUSBModeTest for ARCH=UC3 in device only mode... $(MAKE) -s -f makefile.test clean elf ARCH=UC3 MCU=uc3a0256 CC_FLAGS='-D USB_DEVICE_ONLY' + + @echo Building SingleUSBModeTest for ARCH=UC3 in host only mode... $(MAKE) -s -f makefile.test clean elf ARCH=UC3 MCU=uc3a0256 CC_FLAGS='-D USB_HOST_ONLY' clean: diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/AudioInput/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/AudioInput/makefile index 44f445f3a..1b251cd50 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/AudioInput/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/AudioInput/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/AudioOutput/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/AudioOutput/makefile index f6f6da025..904e13684 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/AudioOutput/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/AudioOutput/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/DualVirtualSerial/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/DualVirtualSerial/makefile index 606c37747..ce751a865 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/DualVirtualSerial/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/DualVirtualSerial/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/GenericHID/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/GenericHID/makefile index 2521616eb..5a4b85bf3 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/GenericHID/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/GenericHID/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Joystick/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Joystick/makefile index 2525a7de4..926a50d81 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Joystick/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Joystick/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Keyboard/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Keyboard/makefile index d8d7ce0d6..346f428dd 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Keyboard/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Keyboard/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/KeyboardMouse/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/KeyboardMouse/makefile index 54cc5522f..4727bb1bf 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/KeyboardMouse/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/KeyboardMouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/KeyboardMouseMultiReport/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/KeyboardMouseMultiReport/makefile index 874dc732d..e27213bd7 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/KeyboardMouseMultiReport/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/KeyboardMouseMultiReport/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MIDI/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MIDI/makefile index 94ed2be30..6e5f7d36e 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MIDI/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MIDI/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MassStorage/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MassStorage/makefile index dc13db9ca..4d2d5d03d 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MassStorage/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MassStorage/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in \ No newline at end of file diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MassStorageKeyboard/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MassStorageKeyboard/makefile index 385e5f6ce..2e410c869 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MassStorageKeyboard/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/MassStorageKeyboard/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Mouse/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Mouse/makefile index 8b3ec13b4..d4781581c 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Mouse/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/Mouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/RNDISEthernet/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/RNDISEthernet/makefile index 042c4f241..80242eadc 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/RNDISEthernet/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/RNDISEthernet/makefile @@ -32,5 +32,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerial/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerial/makefile index 5c1cc1c34..da7c8a38c 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerial/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerial/makefile @@ -28,6 +28,9 @@ all: include $(LUFA_PATH)/Build/lufa.core.in include $(LUFA_PATH)/Build/lufa.sources.in include $(LUFA_PATH)/Build/lufa.build.in +include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in +include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerialMassStorage/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerialMassStorage/makefile index 9587672b5..0665a7f25 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerialMassStorage/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerialMassStorage/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerialMouse/makefile b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerialMouse/makefile index 386cd6502..67e7e365e 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerialMouse/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/ClassDriver/VirtualSerialMouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/Incomplete/Sideshow/makefile b/branches/LUFA-IAR-Port/Demos/Device/Incomplete/Sideshow/makefile index b5a459386..2f032f394 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/Incomplete/Sideshow/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/Incomplete/Sideshow/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h b/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h index e45654a27..17f68f3a3 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h +++ b/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h @@ -1,84 +1,84 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Copyright 2010 Peter Lawrence (majbthrd [at] gmail [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for Descriptors.c. - */ - -#ifndef _DESCRIPTORS_H_ -#define _DESCRIPTORS_H_ - - /* Includes: */ - #include - - #include - - /* Macros: */ - /** Endpoint address of the TMC notification IN endpoint. */ - #define TMC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2) - - /** Endpoint address of the TMC device-to-host data IN endpoint. */ - #define TMC_IN_EPADDR (ENDPOINT_DIR_IN | 3) - - /** Endpoint address of the TMC host-to-device data OUT endpoint. */ - #define TMC_OUT_EPADDR (ENDPOINT_DIR_OUT | 4) - - /** Size in bytes of the TMC data endpoints. */ - #define TMC_IO_EPSIZE 64 - - /** Size in bytes of the TMC notification endpoint. */ - #define TMC_NOTIFICATION_EPSIZE 8 - - /* Type Defines: */ - /** Type define for the device configuration descriptor structure. This must be defined in the - * application code, as the configuration descriptor contains several sub-descriptors which - * vary between devices, and which describe the device's usage to the host. - */ - typedef struct - { - USB_Descriptor_Configuration_Header_t Config; - - // Test and Measurement Interface - USB_Descriptor_Interface_t TM_Interface; - USB_Descriptor_Endpoint_t TM_DataOutEndpoint; - USB_Descriptor_Endpoint_t TM_DataInEndpoint; - USB_Descriptor_Endpoint_t TM_NotificationEndpoint; - } USB_Descriptor_Configuration_t; - - /* Function Prototypes: */ - uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, - const uint8_t wIndex, - const void** const DescriptorAddress) - ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); - -#endif +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Peter Lawrence (majbthrd [at] gmail [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for Descriptors.c. + */ + +#ifndef _DESCRIPTORS_H_ +#define _DESCRIPTORS_H_ + + /* Includes: */ + #include + + #include + + /* Macros: */ + /** Endpoint address of the TMC notification IN endpoint. */ + #define TMC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2) + + /** Endpoint address of the TMC device-to-host data IN endpoint. */ + #define TMC_IN_EPADDR (ENDPOINT_DIR_IN | 3) + + /** Endpoint address of the TMC host-to-device data OUT endpoint. */ + #define TMC_OUT_EPADDR (ENDPOINT_DIR_OUT | 4) + + /** Size in bytes of the TMC data endpoints. */ + #define TMC_IO_EPSIZE 64 + + /** Size in bytes of the TMC notification endpoint. */ + #define TMC_NOTIFICATION_EPSIZE 8 + + /* Type Defines: */ + /** Type define for the device configuration descriptor structure. This must be defined in the + * application code, as the configuration descriptor contains several sub-descriptors which + * vary between devices, and which describe the device's usage to the host. + */ + typedef struct + { + USB_Descriptor_Configuration_Header_t Config; + + // Test and Measurement Interface + USB_Descriptor_Interface_t TM_Interface; + USB_Descriptor_Endpoint_t TM_DataOutEndpoint; + USB_Descriptor_Endpoint_t TM_DataInEndpoint; + USB_Descriptor_Endpoint_t TM_NotificationEndpoint; + } USB_Descriptor_Configuration_t; + + /* Function Prototypes: */ + uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, + const uint8_t wIndex, + const void** const DescriptorAddress) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); + +#endif diff --git a/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h b/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h index bd93154f8..9fa9f23d0 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h +++ b/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h @@ -1,149 +1,149 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#ifndef _TESTANDMEASUREMENT_H_ -#define _TESTANDMEASUREMENT_H_ - - /* Includes: */ - #include - #include - #include - #include - - #include "Descriptors.h" - - #include - #include - - /* Macros: */ - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is busy. */ - #define LEDMASK_USB_BUSY LEDS_LED2 - - #define Req_InitiateAbortBulkOut 0x01 - #define Req_CheckAbortBulkOutStatus 0x02 - #define Req_InitiateAbortBulkIn 0x03 - #define Req_CheckAbortBulkInStatus 0x04 - #define Req_InitiateClear 0x05 - #define Req_CheckClearStatus 0x06 - #define Req_GetCapabilities 0x07 - #define Req_IndicatorPulse 0x40 - - #define TMC_STATUS_SUCCESS 0x01 - #define TMC_STATUS_PENDING 0x02 - #define TMC_STATUS_FAILED 0x80 - #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81 - #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82 - #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83 - - #define TMC_MESSAGEID_DEV_DEP_MSG_OUT 0x01 - #define TMC_MESSAGEID_DEV_DEP_MSG_IN 0x02 - #define TMC_MESSAGEID_DEV_VENDOR_OUT 0x7E - #define TMC_MESSAGEID_DEV_VENDOR_IN 0x7F - - /* Type Defines */ - typedef struct - { - uint8_t Status; - uint8_t Reserved; - - uint16_t TMCVersion; - - struct - { - unsigned ListenOnly : 1; - unsigned TalkOnly : 1; - unsigned PulseIndicateSupported : 1; - unsigned Reserved : 5; - } Interface; - - struct - { - unsigned SupportsAbortINOnMatch : 1; - unsigned Reserved : 7; - } Device; - - uint8_t Reserved2[6]; - uint8_t Reserved3[12]; - } TMC_Capabilities_t; - - typedef struct - { - uint8_t LastMessageTransaction; - uint8_t TermChar; - uint8_t Reserved[2]; - } TMC_DevOUTMessageHeader_t; - - typedef struct - { - uint8_t LastMessageTransaction; - uint8_t Reserved[3]; - } TMC_DevINMessageHeader_t; - - typedef struct - { - uint8_t MessageID; - uint8_t Tag; - uint8_t InverseTag; - uint8_t Reserved; - uint32_t TransferSize; - - union - { - TMC_DevOUTMessageHeader_t DeviceOUT; - TMC_DevINMessageHeader_t DeviceIN; - uint32_t VendorSpecific; - } MessageIDSpecific; - } TMC_MessageHeader_t; - - /* Function Prototypes: */ - void SetupHardware(void); - void TMC_Task(void); - bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader); - bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader); - - void EVENT_USB_Device_Connect(void); - void EVENT_USB_Device_Disconnect(void); - void EVENT_USB_Device_ConfigurationChanged(void); - void EVENT_USB_Device_ControlRequest(void); - -#endif +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#ifndef _TESTANDMEASUREMENT_H_ +#define _TESTANDMEASUREMENT_H_ + + /* Includes: */ + #include + #include + #include + #include + + #include "Descriptors.h" + + #include + #include + + /* Macros: */ + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is busy. */ + #define LEDMASK_USB_BUSY LEDS_LED2 + + #define Req_InitiateAbortBulkOut 0x01 + #define Req_CheckAbortBulkOutStatus 0x02 + #define Req_InitiateAbortBulkIn 0x03 + #define Req_CheckAbortBulkInStatus 0x04 + #define Req_InitiateClear 0x05 + #define Req_CheckClearStatus 0x06 + #define Req_GetCapabilities 0x07 + #define Req_IndicatorPulse 0x40 + + #define TMC_STATUS_SUCCESS 0x01 + #define TMC_STATUS_PENDING 0x02 + #define TMC_STATUS_FAILED 0x80 + #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81 + #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82 + #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83 + + #define TMC_MESSAGEID_DEV_DEP_MSG_OUT 0x01 + #define TMC_MESSAGEID_DEV_DEP_MSG_IN 0x02 + #define TMC_MESSAGEID_DEV_VENDOR_OUT 0x7E + #define TMC_MESSAGEID_DEV_VENDOR_IN 0x7F + + /* Type Defines */ + typedef struct + { + uint8_t Status; + uint8_t Reserved; + + uint16_t TMCVersion; + + struct + { + unsigned ListenOnly : 1; + unsigned TalkOnly : 1; + unsigned PulseIndicateSupported : 1; + unsigned Reserved : 5; + } Interface; + + struct + { + unsigned SupportsAbortINOnMatch : 1; + unsigned Reserved : 7; + } Device; + + uint8_t Reserved2[6]; + uint8_t Reserved3[12]; + } TMC_Capabilities_t; + + typedef struct + { + uint8_t LastMessageTransaction; + uint8_t TermChar; + uint8_t Reserved[2]; + } TMC_DevOUTMessageHeader_t; + + typedef struct + { + uint8_t LastMessageTransaction; + uint8_t Reserved[3]; + } TMC_DevINMessageHeader_t; + + typedef struct + { + uint8_t MessageID; + uint8_t Tag; + uint8_t InverseTag; + uint8_t Reserved; + uint32_t TransferSize; + + union + { + TMC_DevOUTMessageHeader_t DeviceOUT; + TMC_DevINMessageHeader_t DeviceIN; + uint32_t VendorSpecific; + } MessageIDSpecific; + } TMC_MessageHeader_t; + + /* Function Prototypes: */ + void SetupHardware(void); + void TMC_Task(void); + bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader); + bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader); + + void EVENT_USB_Device_Connect(void); + void EVENT_USB_Device_Disconnect(void); + void EVENT_USB_Device_ConfigurationChanged(void); + void EVENT_USB_Device_ControlRequest(void); + +#endif diff --git a/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/makefile b/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/makefile index cbd43194e..f59981dc4 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/Incomplete/TestAndMeasurement/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/AudioInput/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/AudioInput/makefile index 9748d897c..477221cb4 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/AudioInput/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/AudioInput/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/AudioOutput/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/AudioOutput/makefile index 9fa01dd60..38fb012d2 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/AudioOutput/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/AudioOutput/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/DualVirtualSerial/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/DualVirtualSerial/makefile index 81add683c..4cb9057d7 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/DualVirtualSerial/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/DualVirtualSerial/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/GenericHID/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/GenericHID/makefile index 17f61929f..9a35c6d2e 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/GenericHID/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/GenericHID/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Joystick/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Joystick/makefile index 162328652..1e2e6ee45 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Joystick/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Joystick/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Keyboard/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Keyboard/makefile index c1fe9720b..af67b625a 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Keyboard/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Keyboard/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/KeyboardMouse/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/KeyboardMouse/makefile index b89c33d1c..3485e7f83 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/KeyboardMouse/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/KeyboardMouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/MIDI/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/MIDI/makefile index f8c258ff6..5290fe665 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/MIDI/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/MIDI/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/MassStorage/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/MassStorage/makefile index 22bc7eef4..7ea0abfc5 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/MassStorage/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/MassStorage/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Mouse/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Mouse/makefile index ace12363f..5552aee5a 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Mouse/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/Mouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/RNDISEthernet/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/RNDISEthernet/makefile index fe9256774..c6c867be8 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/RNDISEthernet/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/RNDISEthernet/makefile @@ -32,5 +32,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/VirtualSerial/makefile b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/VirtualSerial/makefile index 930c1d202..8ab7f5278 100644 --- a/branches/LUFA-IAR-Port/Demos/Device/LowLevel/VirtualSerial/makefile +++ b/branches/LUFA-IAR-Port/Demos/Device/LowLevel/VirtualSerial/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/DualRole/ClassDriver/MouseHostDevice/makefile b/branches/LUFA-IAR-Port/Demos/DualRole/ClassDriver/MouseHostDevice/makefile index 3458943d4..c30b35361 100644 --- a/branches/LUFA-IAR-Port/Demos/DualRole/ClassDriver/MouseHostDevice/makefile +++ b/branches/LUFA-IAR-Port/Demos/DualRole/ClassDriver/MouseHostDevice/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.c b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.c index 4c53cc221..b1e988cca 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.c +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.c @@ -1,232 +1,232 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Main source file for the AndroidAccessoryHost demo. This file contains the main tasks of - * the demo and is responsible for the initial application hardware configuration. - */ - -#include "AndroidAccessoryHost.h" - -/** LUFA Android Open Accessory Class driver interface configuration and state information. This - * structure is passed to all Android Open Accessory Class driver functions, so that multiple - * instances of the same class within a device can be differentiated from one another. - */ -USB_ClassInfo_AOA_Host_t AndroidDevice_AOA_Interface = - { - .Config = - { - .DataINPipe = - { - .Address = (PIPE_DIR_IN | 1), - .Banks = 1, - }, - .DataOUTPipe = - { - .Address = (PIPE_DIR_OUT | 2), - .Banks = 1, - }, - .PropertyStrings = - { - [AOA_STRING_Manufacturer] = "Dean Camera", - [AOA_STRING_Model] = "LUFA Android Demo", - [AOA_STRING_Description] = "LUFA Android Demo", - [AOA_STRING_Version] = "1.0", - [AOA_STRING_URI] = "http://www.lufa-lib.org", - [AOA_STRING_Serial] = "0000000012345678", - }, - }, - }; - - -/** Main program entry point. This routine configures the hardware required by the application, then - * enters a loop to run the application tasks in sequence. - */ -int main(void) -{ - SetupHardware(); - - puts_P(PSTR(ESC_FG_CYAN "Android Accessory Host Demo running.\r\n" ESC_FG_WHITE)); - - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - sei(); - - for (;;) - { - AOAHost_Task(); - - AOA_Host_USBTask(&AndroidDevice_AOA_Interface); - USB_USBTask(); - } -} - -/** Configures the board hardware and chip peripherals for the demo's functionality. */ -void SetupHardware(void) -{ - /* Disable watchdog if enabled by bootloader/fuses */ - MCUSR &= ~(1 << WDRF); - wdt_disable(); - - /* Disable clock division */ - clock_prescale_set(clock_div_1); - - /* Hardware Initialization */ - Serial_Init(9600, false); - LEDs_Init(); - USB_Init(); - - /* Create a stdio stream for the serial port for stdin and stdout */ - Serial_CreateStream(NULL); -} - -/** Task to manage an enumerated USB Android Accessory device once connected, to print received data - * from the device to the serial port. - */ -void AOAHost_Task(void) -{ - if (USB_HostState != HOST_STATE_Configured) - return; - - if (AOA_Host_BytesReceived(&AndroidDevice_AOA_Interface)) - { - /* Echo received bytes from the attached device through the USART */ - int16_t ReceivedByte = AOA_Host_ReceiveByte(&AndroidDevice_AOA_Interface); - if (!(ReceivedByte < 0)) - putchar(ReceivedByte); - } -} - -/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and - * starts the library USB task to begin the enumeration and USB management process. - */ -void EVENT_USB_Host_DeviceAttached(void) -{ - puts_P(PSTR("Device Attached.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); -} - -/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and - * stops the library USB task management process. - */ -void EVENT_USB_Host_DeviceUnattached(void) -{ - puts_P(PSTR("\r\nDevice Unattached.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); -} - -/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully - * enumerated by the host and is now ready to be used by the application. - */ -void EVENT_USB_Host_DeviceEnumerationComplete(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); - - USB_Descriptor_Device_t DeviceDescriptor; - - if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful) - { - puts_P(PSTR("Error Retrieving Device Descriptor.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - bool NeedModeSwitch; - if (!(AOA_Host_ValidateAccessoryDevice(&AndroidDevice_AOA_Interface, &DeviceDescriptor, &NeedModeSwitch))) - { - puts_P(PSTR("Not an Android device.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - if (NeedModeSwitch) - { - puts_P(PSTR("Not in Accessory mode, switching...\r\n")); - AOA_Host_StartAccessoryMode(&AndroidDevice_AOA_Interface); - return; - } - - uint16_t ConfigDescriptorSize; - uint8_t ConfigDescriptorData[512]; - - if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData, - sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) - { - puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - if (AOA_Host_ConfigurePipes(&AndroidDevice_AOA_Interface, - ConfigDescriptorSize, ConfigDescriptorData) != AOA_ENUMERROR_NoError) - { - puts_P(PSTR("Attached Device Not a Valid Android Accessory Class Device.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful) - { - puts_P(PSTR("Error Setting Device Configuration.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - puts_P(PSTR("Android Device Enumerated.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_READY); -} - -/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ -void EVENT_USB_Host_HostError(const uint8_t ErrorCode) -{ - USB_Disable(); - - printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n" - " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); - - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - for(;;); -} - -/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while - * enumerating an attached USB device. - */ -void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, - const uint8_t SubErrorCode) -{ - printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n" - " -- Error Code %d\r\n" - " -- Sub Error Code %d\r\n" - " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState); - - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); -} - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Main source file for the AndroidAccessoryHost demo. This file contains the main tasks of + * the demo and is responsible for the initial application hardware configuration. + */ + +#include "AndroidAccessoryHost.h" + +/** LUFA Android Open Accessory Class driver interface configuration and state information. This + * structure is passed to all Android Open Accessory Class driver functions, so that multiple + * instances of the same class within a device can be differentiated from one another. + */ +USB_ClassInfo_AOA_Host_t AndroidDevice_AOA_Interface = + { + .Config = + { + .DataINPipe = + { + .Address = (PIPE_DIR_IN | 1), + .Banks = 1, + }, + .DataOUTPipe = + { + .Address = (PIPE_DIR_OUT | 2), + .Banks = 1, + }, + .PropertyStrings = + { + [AOA_STRING_Manufacturer] = "Dean Camera", + [AOA_STRING_Model] = "LUFA Android Demo", + [AOA_STRING_Description] = "LUFA Android Demo", + [AOA_STRING_Version] = "1.0", + [AOA_STRING_URI] = "http://www.lufa-lib.org", + [AOA_STRING_Serial] = "0000000012345678", + }, + }, + }; + + +/** Main program entry point. This routine configures the hardware required by the application, then + * enters a loop to run the application tasks in sequence. + */ +int main(void) +{ + SetupHardware(); + + puts_P(PSTR(ESC_FG_CYAN "Android Accessory Host Demo running.\r\n" ESC_FG_WHITE)); + + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); + sei(); + + for (;;) + { + AOAHost_Task(); + + AOA_Host_USBTask(&AndroidDevice_AOA_Interface); + USB_USBTask(); + } +} + +/** Configures the board hardware and chip peripherals for the demo's functionality. */ +void SetupHardware(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + /* Hardware Initialization */ + Serial_Init(9600, false); + LEDs_Init(); + USB_Init(); + + /* Create a stdio stream for the serial port for stdin and stdout */ + Serial_CreateStream(NULL); +} + +/** Task to manage an enumerated USB Android Accessory device once connected, to print received data + * from the device to the serial port. + */ +void AOAHost_Task(void) +{ + if (USB_HostState != HOST_STATE_Configured) + return; + + if (AOA_Host_BytesReceived(&AndroidDevice_AOA_Interface)) + { + /* Echo received bytes from the attached device through the USART */ + int16_t ReceivedByte = AOA_Host_ReceiveByte(&AndroidDevice_AOA_Interface); + if (!(ReceivedByte < 0)) + putchar(ReceivedByte); + } +} + +/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and + * starts the library USB task to begin the enumeration and USB management process. + */ +void EVENT_USB_Host_DeviceAttached(void) +{ + puts_P(PSTR("Device Attached.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); +} + +/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and + * stops the library USB task management process. + */ +void EVENT_USB_Host_DeviceUnattached(void) +{ + puts_P(PSTR("\r\nDevice Unattached.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); +} + +/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully + * enumerated by the host and is now ready to be used by the application. + */ +void EVENT_USB_Host_DeviceEnumerationComplete(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); + + USB_Descriptor_Device_t DeviceDescriptor; + + if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful) + { + puts_P(PSTR("Error Retrieving Device Descriptor.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + bool NeedModeSwitch; + if (!(AOA_Host_ValidateAccessoryDevice(&AndroidDevice_AOA_Interface, &DeviceDescriptor, &NeedModeSwitch))) + { + puts_P(PSTR("Not an Android device.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + if (NeedModeSwitch) + { + puts_P(PSTR("Not in Accessory mode, switching...\r\n")); + AOA_Host_StartAccessoryMode(&AndroidDevice_AOA_Interface); + return; + } + + uint16_t ConfigDescriptorSize; + uint8_t ConfigDescriptorData[512]; + + if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData, + sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) + { + puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + if (AOA_Host_ConfigurePipes(&AndroidDevice_AOA_Interface, + ConfigDescriptorSize, ConfigDescriptorData) != AOA_ENUMERROR_NoError) + { + puts_P(PSTR("Attached Device Not a Valid Android Accessory Class Device.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful) + { + puts_P(PSTR("Error Setting Device Configuration.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + puts_P(PSTR("Android Device Enumerated.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_READY); +} + +/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ +void EVENT_USB_Host_HostError(const uint8_t ErrorCode) +{ + USB_Disable(); + + printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n" + " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); + + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + for(;;); +} + +/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while + * enumerating an attached USB device. + */ +void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, + const uint8_t SubErrorCode) +{ + printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n" + " -- Error Code %d\r\n" + " -- Sub Error Code %d\r\n" + " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState); + + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); +} + diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.h b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.h index 95cecca5c..000069620 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.h +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.h @@ -1,78 +1,78 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for AndroidAccessoryHost.c. - */ - -#ifndef _ANDROIDACCESSORY_HOST_H_ -#define _ANDROIDACCESSORY_HOST_H_ - - /* Includes: */ - #include - #include - #include - #include - #include - #include - - #include - #include - #include - #include - - /* Macros: */ - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /* Function Prototypes: */ - void SetupHardware(void); - void AOAHost_Task(void); - - void EVENT_USB_Host_HostError(const uint8_t ErrorCode); - void EVENT_USB_Host_DeviceAttached(void); - void EVENT_USB_Host_DeviceUnattached(void); - void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, - const uint8_t SubErrorCode); - void EVENT_USB_Host_DeviceEnumerationComplete(void); - -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for AndroidAccessoryHost.c. + */ + +#ifndef _ANDROIDACCESSORY_HOST_H_ +#define _ANDROIDACCESSORY_HOST_H_ + + /* Includes: */ + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + + /* Macros: */ + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /* Function Prototypes: */ + void SetupHardware(void); + void AOAHost_Task(void); + + void EVENT_USB_Host_HostError(const uint8_t ErrorCode); + void EVENT_USB_Host_DeviceAttached(void); + void EVENT_USB_Host_DeviceUnattached(void); + void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, + const uint8_t SubErrorCode); + void EVENT_USB_Host_DeviceEnumerationComplete(void); + +#endif + diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/makefile index d8d255c4f..2f11b854c 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AndroidAccessoryHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AudioInputHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AudioInputHost/makefile index f51574bdc..46916fcc3 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AudioInputHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AudioInputHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AudioOutputHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AudioOutputHost/makefile index 20d2d85d2..ea54c2e5f 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AudioOutputHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/AudioOutputHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/JoystickHostWithParser/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/JoystickHostWithParser/makefile index 6da44b02e..a170830e5 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/JoystickHostWithParser/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/JoystickHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/KeyboardHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/KeyboardHost/makefile index 21e61af22..fb74d48ee 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/KeyboardHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/KeyboardHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/KeyboardHostWithParser/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/KeyboardHostWithParser/makefile index 3a2d75084..005a79641 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/KeyboardHostWithParser/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/KeyboardHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MIDIHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MIDIHost/makefile index 98c3caef4..998972556 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MIDIHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MIDIHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MassStorageHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MassStorageHost/makefile index 93a2eb272..e2835d243 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MassStorageHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MassStorageHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MouseHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MouseHost/makefile index 0935b8d4d..a20d59d3c 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MouseHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MouseHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MouseHostWithParser/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MouseHostWithParser/makefile index c342fa1fb..6bf3ee3bf 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MouseHostWithParser/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/MouseHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/PrinterHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/PrinterHost/makefile index c83749c91..f4531fcf4 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/PrinterHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/PrinterHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/RNDISEthernetHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/RNDISEthernetHost/makefile index 1565f773f..30e6bfcea 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/RNDISEthernetHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/RNDISEthernetHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/StillImageHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/StillImageHost/makefile index 29a07dc4c..118778a86 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/StillImageHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/StillImageHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/VirtualSerialHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/VirtualSerialHost/makefile index e074f8413..6bd3fbe7a 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/VirtualSerialHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/ClassDriver/VirtualSerialHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AndroidAccessoryHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AndroidAccessoryHost/makefile index bd51e8f53..c8da7e08f 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AndroidAccessoryHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AndroidAccessoryHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AudioInputHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AudioInputHost/makefile index d271e2e46..4f9e8dfae 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AudioInputHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AudioInputHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AudioOutputHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AudioOutputHost/makefile index 8185200d7..bb73504ef 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AudioOutputHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/AudioOutputHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/GenericHIDHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/GenericHIDHost/makefile index 15fb5ec11..cbec54a4c 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/GenericHIDHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/GenericHIDHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/JoystickHostWithParser/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/JoystickHostWithParser/makefile index a3ec3ecf8..6ad028847 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/JoystickHostWithParser/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/JoystickHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/KeyboardHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/KeyboardHost/makefile index 4b98db4af..fe27ca196 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/KeyboardHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/KeyboardHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/KeyboardHostWithParser/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/KeyboardHostWithParser/makefile index 05c7e3fa8..4cc47619d 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/KeyboardHostWithParser/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/KeyboardHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MIDIHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MIDIHost/makefile index 4feb22571..a4a347175 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MIDIHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MIDIHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MassStorageHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MassStorageHost/makefile index 3085cd8ff..0d5520263 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MassStorageHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MassStorageHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MouseHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MouseHost/makefile index cad2b1c26..dc8c671e4 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MouseHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MouseHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MouseHostWithParser/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MouseHostWithParser/makefile index 332bd58eb..d32a20ac7 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MouseHostWithParser/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/MouseHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/PrinterHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/PrinterHost/makefile index 54e3cf67b..7269e122b 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/PrinterHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/PrinterHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/RNDISEthernetHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/RNDISEthernetHost/makefile index e9a152a2a..defb5b2e0 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/RNDISEthernetHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/RNDISEthernetHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/StillImageHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/StillImageHost/makefile index 7aaa7beee..67537f036 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/StillImageHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/StillImageHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/VirtualSerialHost/makefile b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/VirtualSerialHost/makefile index 1f2fcbf9f..8346c8d55 100644 --- a/branches/LUFA-IAR-Port/Demos/Host/LowLevel/VirtualSerialHost/makefile +++ b/branches/LUFA-IAR-Port/Demos/Host/LowLevel/VirtualSerialHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/LUFA.pnproj b/branches/LUFA-IAR-Port/LUFA.pnproj index 1bdc23af4..df32a1d53 100644 --- a/branches/LUFA-IAR-Port/LUFA.pnproj +++ b/branches/LUFA-IAR-Port/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.atprogram.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.atprogram.in index 95b0a9702..f9f5dfc9c 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.atprogram.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.atprogram.in @@ -48,9 +48,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables ATPROGRAM_PROGRAMMER ?= jtagice3 diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.avrdude.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.avrdude.in index 1aa85c113..21f93ef26 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.avrdude.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.avrdude.in @@ -48,9 +48,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables AVRDUDE_PROGRAMMER ?= jtagicemkii @@ -67,13 +69,16 @@ $(call ERROR_IF_EMPTY, AVRDUDE_PORT) # Output Messages MSG_AVRDUDE_CMD := ' [AVRDUDE] :' +# Construct base avrdude command flags +BASE_AVRDUDE_FLAGS := -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) + avrdude: $(TARGET).hex $(MAKEFILE_LIST) @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" FLASH with settings \"$(AVRDUDE_FLASH_FLAGS)\" using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\" - avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U flash:w:$< $(AVRDUDE_FLAGS) + avrdude $(BASE_AVRDUDE_FLAGS) -U flash:w:$< $(AVRDUDE_FLAGS) avrdude-ee: $(TARGET).eep $(MAKEFILE_LIST) @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" EEPROM with settings \"$(AVRDUDE_EEP_FLAGS)\" using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\" - avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U eeprom:w:$< $(AVRDUDE_FLAGS) + avrdude $(BASE_AVRDUDE_FLAGS) -U eeprom:w:$< $(AVRDUDE_FLAGS) # Phony build targets for this module .PHONY: avrdude avrdude-ee diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.build.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.build.in index 78af0d43e..994f4b7fd 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.build.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.build.in @@ -68,9 +68,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables BOARD ?= NONE @@ -114,7 +116,7 @@ endif MSG_BUILD_BEGIN := Begin compilation of project \"$(TARGET)\"... MSG_BUILD_END := Finished building project \"$(TARGET)\". MSG_COMPILE_CMD := ' [GCC] :' -MSG_ASSEMBLE_CMD := ' [AS] :' +MSG_ASSEMBLE_CMD := ' [GAS] :' MSG_NM_CMD := ' [NM] :' MSG_REMOVE_CMD := ' [RM] :' MSG_LINKER_CMD := ' [LNK] :' @@ -145,7 +147,7 @@ endif DEPENDENCY_FILES = $(OBJECT_FILES:%.o=%.d) # Create a list of common flags to pass to the compiler/linker/assembler -BASE_CC_FLAGS := +BASE_CC_FLAGS := -pipe ifeq ($(ARCH), AVR8) BASE_CC_FLAGS += -mmcu=$(MCU) -gdwarf-2 -fshort-enums -fno-inline-small-functions -fpack-struct else ifeq ($(ARCH), XMEGA) diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.core.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.core.in index 96b6df366..f44b407ed 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.core.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.core.in @@ -51,6 +51,8 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- +SHELL = /bin/sh + # Build sorted and filtered lists of the included build module data SORTED_LUFA_BUILD_MODULES = $(sort $(LUFA_BUILD_MODULES)) SORTED_LUFA_BUILD_TARGETS = $(sort $(LUFA_BUILD_TARGETS)) diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.cppcheck.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.cppcheck.in index 66f3aeef5..1593a4279 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.cppcheck.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.cppcheck.in @@ -54,9 +54,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables CPPCHECK_INCLUDES ?= diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.dfu.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.dfu.in index 7eb1fa08e..ba75f14a7 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.dfu.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.dfu.in @@ -46,9 +46,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Sanity-check values of mandatory user-supplied variables $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR))) diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.doxygen.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.doxygen.in index 2d8c28db3..baca62f60 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.doxygen.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.doxygen.in @@ -45,9 +45,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables DOXYGEN_CONF ?= Doxygen.conf diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.hid.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.hid.in new file mode 100644 index 000000000..34d1e2b80 --- /dev/null +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.hid.in @@ -0,0 +1,70 @@ +# +# LUFA Library +# Copyright (C) Dean Camera, 2012. +# +# dean [at] fourwalledcubicle [dot] com +# www.lufa-lib.org +# + +LUFA_BUILD_MODULES += HID +LUFA_BUILD_TARGETS += hid hid-teensy +LUFA_BUILD_MANDATORY_VARS += MCU TARGET +LUFA_BUILD_OPTIONAL_VARS += +LUFA_BUILD_PROVIDED_VARS += +LUFA_BUILD_PROVIDED_MACROS += + +# ----------------------------------------------------------------------------- +# LUFA HID Bootloader Buildsystem Makefile Module. +# ----------------------------------------------------------------------------- +# DESCRIPTION: +# Provides a set of targets to re-program a device currently running a HID +# class bootloader with a project's FLASH files. +# ----------------------------------------------------------------------------- +# TARGETS: +# +# hid - Program FLASH into target via +# hid_bootloader_cli +# hid-teensy - Program FLASH into target via +# teensy_loader_cli +# +# MANDATORY PARAMETERS: +# +# MCU - Microcontroller device model name +# TARGET - Application name +# +# OPTIONAL PARAMETERS: +# +# (None) +# +# PROVIDED VARIABLES: +# +# (None) +# +# PROVIDED MACROS: +# +# (None) +# +# ----------------------------------------------------------------------------- + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) + +# Sanity-check values of mandatory user-supplied variables +$(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR))) +$(call ERROR_IF_EMPTY, MCU) +$(call ERROR_IF_EMPTY, TARGET) + +# Output Messages +MSG_HID_BOOTLOADER_CMD := ' [HID] :' + +hid: $(TARGET).hex $(MAKEFILE_LIST) + @echo $(MSG_HID_BOOTLOADER_CMD) Programming FLASH with hid_bootloader_cli using \"$<\" + hid_bootloader_cli -mmcu=$(MCU) -v $< + +hid-teensy: $(TARGET).hex $(MAKEFILE_LIST) + @echo $(MSG_HID_BOOTLOADER_CMD) Programming FLASH with teensy_loader_cli using \"$<\" + teensy_loader_cli -mmcu=$(MCU) -v $< + +# Phony build targets for this module +.PHONY: hid hid-teensy diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.iar.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.iar.in index 8a6eb4bcd..38ba106bd 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.iar.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.iar.in @@ -141,7 +141,7 @@ ifeq ($(ARCH), AVR8) else ifeq ($(ARCH), XMEGA) BASE_CC_FLAGS += --variable_enum_size enabled else ifeq ($(ARCH), UC3) - BASE_CC_FLAGS += + BASE_CC_FLAGS += --code_model=large --data_model=large endif BASE_CC_FLAGS += --silent --debug --cpu=$(MCU) BASE_CC_FLAGS += -I. -I$(patsubst %/,%,$(LUFA_PATH))/.. @@ -151,14 +151,15 @@ ifneq ($(F_CPU),) endif # Additional language specific compiler flags -BASE_C_FLAGS := -e --diag_suppress Pe546,Pa082 --require_prototypes --variable_enum_size enabled --vla --no_tbaa --char_is_unsigned --discard_unused_publics -O$(OPTIMIZATION) +BASE_C_FLAGS := -e --diag_suppress Pe546,Pa082 --dlib_config DLib_Config_Normal.h --require_prototypes --vla --no_tbaa --char_is_unsigned -O$(OPTIMIZATION) BASE_CPP_FLAGS := $(BASE_C_FLAGS) --$(CPP_STANDARD) BASE_ASM_FLAGS := +# TODO: FIXME! +IAR_PATH := C:\Program\ Files\ \(x86\)\IAR\ Systems\Embedded\ Workbench\ 6.0\ Kickstart + # Create a list of flags to pass to the linker -BASE_LD_FLAGS := -# TODO: -# -f "C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.0 Kickstart\avr32\config\lnk$(MCU:at32%=%).xcl" -D_SSTACK_SIZE=1000 -D_CSTACK_SIZE=2000 -D_HEAP_SIZE=1000 -I"C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.0 Kickstart\avr32\LIB\" -rt -s __program_start -g__init_all_ihandlers -g__handle_all_exceptions +BASE_LD_FLAGS := -l $(TARGET).map $(IAR_PATH)\avr32\lib\dlavr32allasn.r82 -f $(IAR_PATH)\avr32\config\lnk$(MCU:at32%=%).xcl -D_SSTACK_SIZE=1000 -D_CSTACK_SIZE=2000 -D_HEAP_SIZE=1000 -I$(IAR_PATH)\avr32\LIB\ -rt -s __program_start -g__init_all_ihandlers -g__handle_all_exceptions build_begin: @echo "" @@ -183,7 +184,7 @@ clean: @echo $(MSG_REMOVE_CMD) Removing dependency files of \"$(TARGET)\" rm -f $(DEPENDENCY_FILES) @echo $(MSG_REMOVE_CMD) Removing output files of \"$(TARGET)\" - rm -f $(TARGET).elf $(TARGET).hex + rm -f $(TARGET).elf $(TARGET).hex $(TARGET).map all: build_begin check_source elf hex build_end @@ -206,7 +207,7 @@ $(OBJDIR)/%.o: %.S $(MAKEFILE_LIST) .SECONDARY : %.elf %.elf: $(OBJECT_FILES) @echo $(MSG_LINKER_CMD) Linking object files into \"$@\" - xlink $(BASE_LD_FLAGS) $(LD_FLAGS) -c$(CROSS) -Felf -yp -S $^ -o $@ + xlink $(BASE_LD_FLAGS) $(LD_FLAGS) -Felf -yp -S $^ -o $@ %.hex : $(OBJECT_FILES) @echo $(MSG_LINKER_CMD) Linking object files into \"$@\" diff --git a/branches/LUFA-IAR-Port/LUFA/Build/lufa.sources.in b/branches/LUFA-IAR-Port/LUFA/Build/lufa.sources.in index d5316ba87..a475ece09 100644 --- a/branches/LUFA-IAR-Port/LUFA/Build/lufa.sources.in +++ b/branches/LUFA-IAR-Port/LUFA/Build/lufa.sources.in @@ -52,9 +52,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Sanity check user supplied values $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR))) diff --git a/branches/LUFA-IAR-Port/LUFA/CodeTemplates/makefile_template b/branches/LUFA-IAR-Port/LUFA/CodeTemplates/makefile_template index fd53e3706..cf2b6737c 100644 --- a/branches/LUFA-IAR-Port/LUFA/CodeTemplates/makefile_template +++ b/branches/LUFA-IAR-Port/LUFA/CodeTemplates/makefile_template @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/LUFA/Common/Attributes.h b/branches/LUFA-IAR-Port/LUFA/Common/Attributes.h index 225c3ef90..0ab15a5bb 100644 --- a/branches/LUFA-IAR-Port/LUFA/Common/Attributes.h +++ b/branches/LUFA-IAR-Port/LUFA/Common/Attributes.h @@ -145,7 +145,7 @@ #define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes))) #elif defined(__ICCAVR32__) #if !defined(__DOXYGEN__) - #define __IAR_PRAGMA(x) _Pragma(#x) + #define __IAR_ATTR_PRAGMA(...) _Pragma(#__VA_ARGS__) #endif #define ATTR_NO_RETURN __noreturn @@ -153,7 +153,7 @@ #define ATTR_NON_NULL_PTR_ARG(...) #define ATTR_NAKED #define ATTR_NO_INLINE - #define ATTR_ALWAYS_INLINE /*__IAR_PRAGMA(inline = forced)*/ + #define ATTR_ALWAYS_INLINE /*__IAR_ATTR_PRAGMA(inline = forced)*/ #define ATTR_PURE #define ATTR_CONST #define ATTR_DEPRECATED @@ -161,8 +161,8 @@ #define ATTR_NO_INIT __no_init #define ATTR_INIT_SECTION(SectionIndex) #define ATTR_ALIAS(Func) - #define ATTR_PACKED - #define ATTR_ALIGNED(Bytes) __IAR_PRAGMA(data_alignment = Bytes) + #define ATTR_PACKED __IAR_ATTR_PRAGMA(pack(1)) + #define ATTR_ALIGNED(Bytes) __IAR_ATTR_PRAGMA(data_alignment = Bytes) #endif #endif diff --git a/branches/LUFA-IAR-Port/LUFA/Common/Common.h b/branches/LUFA-IAR-Port/LUFA/Common/Common.h index f9bf86a51..2b69b4f82 100644 --- a/branches/LUFA-IAR-Port/LUFA/Common/Common.h +++ b/branches/LUFA-IAR-Port/LUFA/Common/Common.h @@ -150,14 +150,14 @@ * as a discrete block and not as a list of separate statements which may cause problems when used as * a block (such as inline \c if statements). */ - #define MACROS do + #define MACROS do /** Macro for encasing other multi-statement macros. This should be used along with a preceding closing * brace at the end of any multi-statement macro, so that the macros contents as a whole are treated * as a discrete block and not as a list of separate statements which may cause problems when used as * a block (such as inline \c if statements). */ - #define MACROE while (0) + #define MACROE while (0) /** Convenience macro to determine the larger of two values. * @@ -170,7 +170,7 @@ * \return The larger of the two input parameters */ #if !defined(MAX) || defined(__DOXYGEN__) - #define MAX(x, y) (((x) > (y)) ? (x) : (y)) + #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #endif /** Convenience macro to determine the smaller of two values. @@ -184,7 +184,7 @@ * \return The smaller of the two input parameters */ #if !defined(MIN) || defined(__DOXYGEN__) - #define MIN(x, y) (((x) < (y)) ? (x) : (y)) + #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #endif #if !defined(STRINGIFY) || defined(__DOXYGEN__) @@ -195,7 +195,7 @@ * * \return String version of the input. */ - #define STRINGIFY(x) #x + #define STRINGIFY(...) #__VA_ARGS__ /** Converts the given input into a string after macro expansion, via the C Preprocessor. This macro puts * literal quotation marks around the expanded input, converting the source into a string literal. @@ -204,15 +204,15 @@ * * \return String version of the expanded input. */ - #define STRINGIFY_EXPANDED(x) STRINGIFY(x) + #define STRINGIFY_EXPANDED(...) STRINGIFY(__VA_ARGS__) #endif - #define MEMORY_BARRIER() __COMPILER_SPECIFIC(MEMORY_BARRIER()) - #define IS_PART_DEFINED(x) __COMPILER_SPECIFIC(IS_PART_DEFINED(x)) - #define READ_SYS_REGISTER(Reg) __COMPILER_SPECIFIC(READ_SYS_REGISTER(Reg)) - #define WRITE_SYS_REGISTER(Reg, Val) __COMPILER_SPECIFIC(WRITE_SYS_REGISTER(Reg, Val)) - #define CLEAR_STATUS_FLAG(Bitmask) __COMPILER_SPECIFIC(CLEAR_STATUS_FLAG(Bitmask)) - #define SET_STATUS_FLAG(Bitmask) __COMPILER_SPECIFIC(SET_STATUS_FLAG(Bitmask)) + #define MEMORY_BARRIER() __COMPILER_SPECIFIC(MEMORY_BARRIER()) + #define IS_PART_DEFINED(x) __COMPILER_SPECIFIC(IS_PART_DEFINED(x)) + #define READ_SYS_REGISTER(Reg) __COMPILER_SPECIFIC(READ_SYS_REGISTER(Reg)) + #define WRITE_SYS_REGISTER(Reg, Val) __COMPILER_SPECIFIC(WRITE_SYS_REGISTER(Reg, Val)) + #define CLEAR_STATUS_FLAG(Bitmask) __COMPILER_SPECIFIC(CLEAR_STATUS_FLAG(Bitmask)) + #define SET_STATUS_FLAG(Bitmask) __COMPILER_SPECIFIC(SET_STATUS_FLAG(Bitmask)) #if !defined(ISR) || defined(__DOXYGEN__) /** Macro for the definition of interrupt service routines, so that the compiler can insert the required @@ -229,7 +229,7 @@ * * \param[in] Name Unique name of the interrupt service routine. */ - #define ISR(Name, ...) __COMPILER_SPECIFIC(ISR(Name, __VA_ARGS__)) + #define ISR(Name, ...) __COMPILER_SPECIFIC(ISR(Name, __VA_ARGS__)) #endif /* Inline Functions: */ diff --git a/branches/LUFA-IAR-Port/LUFA/Common/CompilerSpecific.h b/branches/LUFA-IAR-Port/LUFA/Common/CompilerSpecific.h index 09006aaaf..527862952 100644 --- a/branches/LUFA-IAR-Port/LUFA/Common/CompilerSpecific.h +++ b/branches/LUFA-IAR-Port/LUFA/Common/CompilerSpecific.h @@ -125,7 +125,11 @@ #define IAR_IS_PART_DEFINED(x) defined(__AT32 ## x ## __) #endif - #define IAR_ISR(Name, ...) __interrupt void Name (void); __interrupt void Name (void) + #if !defined(__DOXYGEN__) + #define __IAR_ISR_PRAGMA(...) _Pragma(#__VA_ARGS__) + #endif + + #define IAR_ISR(Name, Group, Level) __IAR_ISR_PRAGMA(handler = Group, Level) __interrupt void Name (void) #define IAR_READ_SYS_REGISTER(Reg) __get_system_register(Reg) #define IAR_WRITE_SYS_REGISTER(Reg, Val) __set_system_register(Reg, Val) diff --git a/branches/LUFA-IAR-Port/LUFA/DoxygenPages/BuildSystem.txt b/branches/LUFA-IAR-Port/LUFA/DoxygenPages/BuildSystem.txt index 61087a5ce..0d7d6be74 100644 --- a/branches/LUFA-IAR-Port/LUFA/DoxygenPages/BuildSystem.txt +++ b/branches/LUFA-IAR-Port/LUFA/DoxygenPages/BuildSystem.txt @@ -38,6 +38,7 @@ * \li \subpage Page_BuildModule_CPPCHECK - Static Code Analysis * \li \subpage Page_BuildModule_DFU - Device Programming * \li \subpage Page_BuildModule_DOXYGEN - Automated Source Code Documentation + * \li \subpage Page_BuildModule_HID - Device Programming * \li \subpage Page_BuildModule_SOURCES - LUFA Module Source Code Variables */ @@ -512,11 +513,12 @@ * * The DFU programming utility LUFA build system module, providing targets to reprogram an * Atmel processor FLASH and EEPROM memories with a project's compiled binary output files. - * This module requires a DFU class bootloader to be running in the target. + * This module requires a DFU class bootloader to be running in the target, compatible with + * the DFU bootloader protocol as published by Atmel. * * To use this module in your application makefile, add the following code: * \code - * include $(LUFA_PATH)/Build/lufa.dfu.in + * include $(LUFA_PATH)/Build/lufa.dfu.in * \endcode * * \section SSec_BuildModule_DFU_Requirements Requirements @@ -653,6 +655,75 @@ * */ + /** \page Page_BuildModule_HID The HID build module + * + * The HID programming utility LUFA build system module, providing targets to reprogram an + * Atmel processor's FLASH memory with a project's compiled binary output file. This module + * requires a HID class bootloader to be running in the target, using a protocol compatible + * with the PJRC "HalfKay" protocol (http://www.pjrc.com/teensy/halfkay_protocol.html). + * + * To use this module in your application makefile, add the following code: + * \code + * include $(LUFA_PATH)/Build/lufa.hid.in + * \endcode + * + * \section SSec_BuildModule_HID_Requirements Requirements + * This module requires either the hid_bootloader_cli utility from the included LUFA HID + * class bootloader API subdirectory, or the teensy_loader_cli utility from PJRC + * (http://www.pjrc.com/teensy/loader_cli.html) to be available in your system's PATH + * variable. + * + * \section SSec_BuildModule_HID_Targets Targets + * + * + * + * + * + * + * + * + * + * + *
hidProgram the device FLASH memory with the application's executable data using hid_bootloader_cli.
hid-teensyProgram the device EEPROM memory with the application's executable data using teensy_loader_cli.
+ * + * \section SSec_BuildModule_HID_MandatoryParams Mandatory Parameters + * + * + * + * + * + * + * + * + * + * + *
MCUName of the Atmel processor model (e.g. at90usb1287).
TARGETName of the application output file prefix (e.g. TestApplication).
+ * + * \section SSec_BuildModule_HID_OptionalParams Optional Parameters + * + * + * + * + * + *
None
+ * + * \section SSec_BuildModule_HID_ProvideVariables Module Provided Variables + * + * + * + * + * + *
None
+ * + * \section SSec_BuildModule_HID_ProvidedMacros Module Provided Macros + * + * + * + * + * + *
None
+ */ + /** \page Page_BuildModule_SOURCES The SOURCES build module * * The SOURCES LUFA build system module, providing variables listing the various LUFA source files diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/MICROPENDOUS/Buttons.h b/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/MICROPENDOUS/Buttons.h index 731d1b05b..60d81b782 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/MICROPENDOUS/Buttons.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/MICROPENDOUS/Buttons.h @@ -1,208 +1,208 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Board specific Buttons driver header for the Micropendous series boards. - * \copydetails Group_Buttons_MICROPENDOUS_32U2 - * - * \note This file should not be included directly. It is automatically included as needed by the Buttons driver - * dispatch header located in LUFA/Drivers/Board/Buttons.h. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_A MICROPENDOUS_A - * \brief Board specific Button driver header for the Micropendous A (https://code.google.com/p/micropendous/wiki/MicropendousA). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_1 MICROPENDOUS_1 - * \brief Board specific Button driver header for the Micropendous 1 (https://code.google.com/p/micropendous/wiki/Micropendous1). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_2 MICROPENDOUS_2 - * \brief Board specific Button driver header for the Micropendous 2 (https://code.google.com/p/micropendous/wiki/Micropendous2). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_3 MICROPENDOUS_3 - * \brief Board specific Button driver header for the Micropendous 3 (https://code.google.com/p/micropendous/wiki/Micropendous3). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_4 MICROPENDOUS_4 - * \brief Board specific Button driver header for the Micropendous 4 (https://code.google.com/p/micropendous/wiki/Micropendous4). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_DIP MICROPENDOUS_DIP - * \brief Board specific Button driver header for the Micropendous DIP (https://code.google.com/p/micropendous/wiki/MicropendousDIP). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_REV1 MICROPENDOUS_REV1 - * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 1 (https://code.google.com/p/micropendous/wiki/Micropendous). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_REV2 MICROPENDOUS_REV2 - * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 2 (https://code.google.com/p/micropendous/wiki/Micropendous). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_32U2 MICROPENDOUS_32U2 - * \brief Board specific Buttons driver header for the Micropendous 32U2. - * - * \note There are multiple supported Micropendous boards, compile with BOARD = MICROPENDOUS_{VERSION}. - * - * Board specific Buttons driver header for the Micropendous 32U2 (https://code.google.com/p/micropendous/wiki/Micropendous_32U2). - * - * BOARD_MICROPENDOUS_1 and BOARD_MICROPENDOUS_32U2: - * - * - * - *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTD.7
- * - * Other Revisions: - * - * - * - *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTE.2
- * - * @{ - */ - -#ifndef __BUTTONS_MICROPENDOUS_H__ -#define __BUTTONS_MICROPENDOUS_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_BUTTONS_H) - #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. - #endif - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - #if (BOARD == BOARD_MICROPENDOUS_32U2) - #define _BOARD_BUTTON1_MASK (1 << 7) - #define _BOARD_BUTTON_PORTLETTER D - #elif (BOARD == BOARD_MICROPENDOUS_A) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_1) - #define _BOARD_BUTTON1_MASK (1 << 7) - #define _BOARD_BUTTON_PORTLETTER D - #elif (BOARD == BOARD_MICROPENDOUS_2) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_3) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_4) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_DIP) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_REV1) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_REV2) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #endif - - #define _BOARD_BUTTON_CONCAT2(Reg, Letter) Reg ## Letter - #define _BOARD_BUTTON_CONCAT(Reg, Letter) _BOARD_BUTTON_CONCAT2(Reg, Letter) - - #define _BOARD_BUTTON_PORT _BOARD_BUTTON_CONCAT(PORT, _BOARD_BUTTON_PORTLETTER) - #define _BOARD_BUTTON_PIN _BOARD_BUTTON_CONCAT(PIN, _BOARD_BUTTON_PORTLETTER) - #define _BOARD_BUTTON_DDR _BOARD_BUTTON_CONCAT(DDR, _BOARD_BUTTON_PORTLETTER) - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Button mask for the first button on the board. */ - #define BUTTONS_BUTTON1 _BOARD_BUTTON1_MASK - - /* Inline Functions: */ - #if !defined(__DOXYGEN__) - static inline void Buttons_Init(void) - { - _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1; - _BOARD_BUTTON_PORT |= BUTTONS_BUTTON1; - } - - static inline void Buttons_Disable(void) - { - _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1; - _BOARD_BUTTON_PORT &= ~BUTTONS_BUTTON1; - } - - static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; - static inline uint8_t Buttons_GetStatus(void) - { - return ((_BOARD_BUTTON_PIN & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1); - } - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific Buttons driver header for the Micropendous series boards. + * \copydetails Group_Buttons_MICROPENDOUS_32U2 + * + * \note This file should not be included directly. It is automatically included as needed by the Buttons driver + * dispatch header located in LUFA/Drivers/Board/Buttons.h. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_A MICROPENDOUS_A + * \brief Board specific Button driver header for the Micropendous A (https://code.google.com/p/micropendous/wiki/MicropendousA). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_1 MICROPENDOUS_1 + * \brief Board specific Button driver header for the Micropendous 1 (https://code.google.com/p/micropendous/wiki/Micropendous1). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_2 MICROPENDOUS_2 + * \brief Board specific Button driver header for the Micropendous 2 (https://code.google.com/p/micropendous/wiki/Micropendous2). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_3 MICROPENDOUS_3 + * \brief Board specific Button driver header for the Micropendous 3 (https://code.google.com/p/micropendous/wiki/Micropendous3). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_4 MICROPENDOUS_4 + * \brief Board specific Button driver header for the Micropendous 4 (https://code.google.com/p/micropendous/wiki/Micropendous4). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_DIP MICROPENDOUS_DIP + * \brief Board specific Button driver header for the Micropendous DIP (https://code.google.com/p/micropendous/wiki/MicropendousDIP). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_REV1 MICROPENDOUS_REV1 + * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 1 (https://code.google.com/p/micropendous/wiki/Micropendous). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_REV2 MICROPENDOUS_REV2 + * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 2 (https://code.google.com/p/micropendous/wiki/Micropendous). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_32U2 MICROPENDOUS_32U2 + * \brief Board specific Buttons driver header for the Micropendous 32U2. + * + * \note There are multiple supported Micropendous boards, compile with BOARD = MICROPENDOUS_{VERSION}. + * + * Board specific Buttons driver header for the Micropendous 32U2 (https://code.google.com/p/micropendous/wiki/Micropendous_32U2). + * + * BOARD_MICROPENDOUS_1 and BOARD_MICROPENDOUS_32U2: + * + * + * + *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTD.7
+ * + * Other Revisions: + * + * + * + *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTE.2
+ * + * @{ + */ + +#ifndef __BUTTONS_MICROPENDOUS_H__ +#define __BUTTONS_MICROPENDOUS_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_BUTTONS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + #if (BOARD == BOARD_MICROPENDOUS_32U2) + #define _BOARD_BUTTON1_MASK (1 << 7) + #define _BOARD_BUTTON_PORTLETTER D + #elif (BOARD == BOARD_MICROPENDOUS_A) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_1) + #define _BOARD_BUTTON1_MASK (1 << 7) + #define _BOARD_BUTTON_PORTLETTER D + #elif (BOARD == BOARD_MICROPENDOUS_2) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_3) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_4) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_DIP) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_REV1) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_REV2) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #endif + + #define _BOARD_BUTTON_CONCAT2(Reg, Letter) Reg ## Letter + #define _BOARD_BUTTON_CONCAT(Reg, Letter) _BOARD_BUTTON_CONCAT2(Reg, Letter) + + #define _BOARD_BUTTON_PORT _BOARD_BUTTON_CONCAT(PORT, _BOARD_BUTTON_PORTLETTER) + #define _BOARD_BUTTON_PIN _BOARD_BUTTON_CONCAT(PIN, _BOARD_BUTTON_PORTLETTER) + #define _BOARD_BUTTON_DDR _BOARD_BUTTON_CONCAT(DDR, _BOARD_BUTTON_PORTLETTER) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Button mask for the first button on the board. */ + #define BUTTONS_BUTTON1 _BOARD_BUTTON1_MASK + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Buttons_Init(void) + { + _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1; + _BOARD_BUTTON_PORT |= BUTTONS_BUTTON1; + } + + static inline void Buttons_Disable(void) + { + _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1; + _BOARD_BUTTON_PORT &= ~BUTTONS_BUTTON1; + } + + static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Buttons_GetStatus(void) + { + return ((_BOARD_BUTTON_PIN & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/USB2AX/Buttons.h b/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/USB2AX/Buttons.h index 73d05a5b3..cb0eecdf6 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/USB2AX/Buttons.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/USB2AX/Buttons.h @@ -1,113 +1,113 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX. - * \copydetails Group_Buttons_USB2AX - * - * \note This file should not be included directly. It is automatically included as needed by the Buttons driver - * dispatch header located in LUFA/Drivers/Board/Buttons.h. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_USB2AX_V3 USB2AX_V3 - * \brief Board specific Button driver header for the Paranoid Studio USB2AX revision 3. - * - * See \ref Group_Buttons_USB2AX for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_USB2AX USB2AX - * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX. - * - * \note For version 3 USB2AX boards, compile with BOARD = USB2AX_V3. - * - * Board specific Buttons driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX). - * - * - * - * - *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTD.7
- * - * @{ - */ - -#ifndef __BUTTONS_USB2AX_H__ -#define __BUTTONS_USB2AX_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_BUTTONS_H) - #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Button mask for the first button on the board. */ - #define BUTTONS_BUTTON1 (1 << 7) - - /* Inline Functions: */ - #if !defined(__DOXYGEN__) - static inline void Buttons_Init(void) - { - DDRD &= ~BUTTONS_BUTTON1; - PORTD |= BUTTONS_BUTTON1; - } - - static inline void Buttons_Disable(void) - { - DDRD &= ~BUTTONS_BUTTON1; - PORTD &= ~BUTTONS_BUTTON1; - } - - static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; - static inline uint8_t Buttons_GetStatus(void) - { - return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1); - } - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX. + * \copydetails Group_Buttons_USB2AX + * + * \note This file should not be included directly. It is automatically included as needed by the Buttons driver + * dispatch header located in LUFA/Drivers/Board/Buttons.h. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_USB2AX_V3 USB2AX_V3 + * \brief Board specific Button driver header for the Paranoid Studio USB2AX revision 3. + * + * See \ref Group_Buttons_USB2AX for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_USB2AX USB2AX + * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX. + * + * \note For version 3 USB2AX boards, compile with BOARD = USB2AX_V3. + * + * Board specific Buttons driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX). + * + * + * + * + *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTD.7
+ * + * @{ + */ + +#ifndef __BUTTONS_USB2AX_H__ +#define __BUTTONS_USB2AX_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_BUTTONS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Button mask for the first button on the board. */ + #define BUTTONS_BUTTON1 (1 << 7) + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Buttons_Init(void) + { + DDRD &= ~BUTTONS_BUTTON1; + PORTD |= BUTTONS_BUTTON1; + } + + static inline void Buttons_Disable(void) + { + DDRD &= ~BUTTONS_BUTTON1; + PORTD &= ~BUTTONS_BUTTON1; + } + + static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Buttons_GetStatus(void) + { + return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/USB2AX/LEDs.h b/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/USB2AX/LEDs.h index 12fa73cd1..364c88de2 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/USB2AX/LEDs.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/Board/AVR8/USB2AX/LEDs.h @@ -1,196 +1,196 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Board specific LED driver header for the Paranoid Studio USB2AX. - * \copydetails Group_LEDs_USB2AX - * - * \note This file should not be included directly. It is automatically included as needed by the LEDs driver - * dispatch header located in LUFA/Drivers/Board/LEDs.h. - */ - -/** \ingroup Group_LEDs - * \defgroup Group_LEDs_USB2AX_V3 USB2AX_V3 - * \brief Board specific LED driver header for the Paranoid Studio USB2AX revision 3. - * - * See \ref Group_LEDs_USB2AX for more details. - */ - -/** \ingroup Group_LEDs - * \defgroup Group_LEDs_USB2AX USB2AX - * \brief Board specific LED driver header for the Paranoid Studio USB2AX. - * - * \note For version 3 USB2AX boards, compile with BOARD = USB2AX_V3. - * - * Board specific LED driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX). - * - * USB2AX: - * - * - * - *
NameColorInfoActive LevelPort Pin
LEDS_LED1GreenGeneral IndicatorHighPORTC.6
- * - * USB2AX_V3: - * - * - * - *
NameColorInfoActive LevelPort Pin
LEDS_LED1GreenGeneral IndicatorHighPORTD.1
- * - * @{ - */ - -#ifndef __LEDS_USB2AX_H__ -#define __LEDS_USB2AX_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_LEDS_H) - #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead. - #endif - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - /* Macros: */ - #if (BOARD == BOARD_USB2AX) - #define USB2AX_LEDS_LED1 (1 << 6) - #else - #define USB2AX_LEDS_LED1 (1 << 1) - #endif - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** LED mask for the first LED on the board. */ - #define LEDS_LED1 USB2AX_LEDS_LED1 - - /** LED mask for all the LEDs on the board. */ - #define LEDS_ALL_LEDS LEDS_LED1 - - /** LED mask for none of the board LEDs. */ - #define LEDS_NO_LEDS 0 - - /* Inline Functions: */ - #if !defined(__DOXYGEN__) - static inline void LEDs_Init(void) - { - #if (BOARD == BOARD_USB2AX) - DDRC |= LEDS_ALL_LEDS; - PORTC &= ~LEDS_ALL_LEDS; - #else - DDRD |= LEDS_ALL_LEDS; - PORTD &= ~LEDS_ALL_LEDS; - #endif - } - - static inline void LEDs_Disable(void) - { - #if (BOARD == BOARD_USB2AX) - DDRC &= ~LEDS_ALL_LEDS; - PORTC &= ~LEDS_ALL_LEDS; - #else - DDRD &= ~LEDS_ALL_LEDS; - PORTD &= ~LEDS_ALL_LEDS; - #endif - } - - static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) - { - #if (BOARD == BOARD_USB2AX) - PORTC |= LEDMask; - #else - PORTD |= LEDMask; - #endif - } - - static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) - { - #if (BOARD == BOARD_USB2AX) - PORTC &= ~LEDMask; - #else - PORTD &= ~LEDMask; - #endif - } - - static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) - { - #if (BOARD == BOARD_USB2AX) - PORTC = ((PORTC & ~LEDS_ALL_LEDS) | LEDMask); - #else - PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask); - #endif - } - - static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, - const uint8_t ActiveMask) - { - #if (BOARD == BOARD_USB2AX) - PORTC = ((PORTC & ~LEDMask) | ActiveMask); - #else - PORTD = ((PORTD & ~LEDMask) | ActiveMask); - #endif - } - - static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) - { - #if (BOARD == BOARD_USB2AX) - PINC = LEDMask; - #else - PIND = LEDMask; - #endif - } - - static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; - static inline uint8_t LEDs_GetLEDs(void) - { - #if (BOARD == BOARD_USB2AX) - return (PORTC & LEDS_ALL_LEDS); - #else - return (PORTD & LEDS_ALL_LEDS); - #endif - } - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific LED driver header for the Paranoid Studio USB2AX. + * \copydetails Group_LEDs_USB2AX + * + * \note This file should not be included directly. It is automatically included as needed by the LEDs driver + * dispatch header located in LUFA/Drivers/Board/LEDs.h. + */ + +/** \ingroup Group_LEDs + * \defgroup Group_LEDs_USB2AX_V3 USB2AX_V3 + * \brief Board specific LED driver header for the Paranoid Studio USB2AX revision 3. + * + * See \ref Group_LEDs_USB2AX for more details. + */ + +/** \ingroup Group_LEDs + * \defgroup Group_LEDs_USB2AX USB2AX + * \brief Board specific LED driver header for the Paranoid Studio USB2AX. + * + * \note For version 3 USB2AX boards, compile with BOARD = USB2AX_V3. + * + * Board specific LED driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX). + * + * USB2AX: + * + * + * + *
NameColorInfoActive LevelPort Pin
LEDS_LED1GreenGeneral IndicatorHighPORTC.6
+ * + * USB2AX_V3: + * + * + * + *
NameColorInfoActive LevelPort Pin
LEDS_LED1GreenGeneral IndicatorHighPORTD.1
+ * + * @{ + */ + +#ifndef __LEDS_USB2AX_H__ +#define __LEDS_USB2AX_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_LEDS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #if (BOARD == BOARD_USB2AX) + #define USB2AX_LEDS_LED1 (1 << 6) + #else + #define USB2AX_LEDS_LED1 (1 << 1) + #endif + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** LED mask for the first LED on the board. */ + #define LEDS_LED1 USB2AX_LEDS_LED1 + + /** LED mask for all the LEDs on the board. */ + #define LEDS_ALL_LEDS LEDS_LED1 + + /** LED mask for none of the board LEDs. */ + #define LEDS_NO_LEDS 0 + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void LEDs_Init(void) + { + #if (BOARD == BOARD_USB2AX) + DDRC |= LEDS_ALL_LEDS; + PORTC &= ~LEDS_ALL_LEDS; + #else + DDRD |= LEDS_ALL_LEDS; + PORTD &= ~LEDS_ALL_LEDS; + #endif + } + + static inline void LEDs_Disable(void) + { + #if (BOARD == BOARD_USB2AX) + DDRC &= ~LEDS_ALL_LEDS; + PORTC &= ~LEDS_ALL_LEDS; + #else + DDRD &= ~LEDS_ALL_LEDS; + PORTD &= ~LEDS_ALL_LEDS; + #endif + } + + static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) + { + #if (BOARD == BOARD_USB2AX) + PORTC |= LEDMask; + #else + PORTD |= LEDMask; + #endif + } + + static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) + { + #if (BOARD == BOARD_USB2AX) + PORTC &= ~LEDMask; + #else + PORTD &= ~LEDMask; + #endif + } + + static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) + { + #if (BOARD == BOARD_USB2AX) + PORTC = ((PORTC & ~LEDS_ALL_LEDS) | LEDMask); + #else + PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask); + #endif + } + + static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, + const uint8_t ActiveMask) + { + #if (BOARD == BOARD_USB2AX) + PORTC = ((PORTC & ~LEDMask) | ActiveMask); + #else + PORTD = ((PORTD & ~LEDMask) | ActiveMask); + #endif + } + + static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) + { + #if (BOARD == BOARD_USB2AX) + PINC = LEDMask; + #else + PIND = LEDMask; + #endif + } + + static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t LEDs_GetLEDs(void) + { + #if (BOARD == BOARD_USB2AX) + return (PORTC & LEDS_ALL_LEDS); + #else + return (PORTD & LEDS_ALL_LEDS); + #endif + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/AndroidAccessoryClass.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/AndroidAccessoryClass.h index 3cede6026..7b1fbfcc2 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/AndroidAccessoryClass.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/AndroidAccessoryClass.h @@ -1,76 +1,76 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Master include file for the library USB Android Open Accessory Class driver. - * - * Master include file for the library USB Android Open Accessory Class driver, for both host and device modes, where available. - * - * This file should be included in all user projects making use of this optional class driver, instead of - * including any headers in the USB/ClassDriver/Device, USB/ClassDriver/Host or USB/ClassDriver/Common subdirectories. - */ - -/** \ingroup Group_USBClassDrivers - * \defgroup Group_USBClassAOA Android Open Accessory Class Driver - * - * \section Sec_Dependencies Module Source Dependencies - * The following files must be built with any user project that uses this module: - * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) - * - * \section Sec_ModDescription Module Description - * Android Open Accessory Class Driver module. This module contains an internal implementation of the USB Android Open Accessory - * Class, for Host USB mode. User applications can use this class driver instead of implementing the Android Open Accessory Class - * manually via the low-level LUFA APIs. - * - * This module is designed to simplify the user code by exposing only the required interface needed to interface with - * Host using the USB Android Open Accessory Class. - * - * @{ - */ - -#ifndef _AOA_CLASS_H_ -#define _AOA_CLASS_H_ - - /* Macros: */ - #define __INCLUDE_FROM_USB_DRIVER - #define __INCLUDE_FROM_AOA_DRIVER - - /* Includes: */ - #include "../Core/USBMode.h" - - #if defined(USB_CAN_BE_HOST) - #include "Host/AndroidAccessoryClassHost.h" - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Master include file for the library USB Android Open Accessory Class driver. + * + * Master include file for the library USB Android Open Accessory Class driver, for both host and device modes, where available. + * + * This file should be included in all user projects making use of this optional class driver, instead of + * including any headers in the USB/ClassDriver/Device, USB/ClassDriver/Host or USB/ClassDriver/Common subdirectories. + */ + +/** \ingroup Group_USBClassDrivers + * \defgroup Group_USBClassAOA Android Open Accessory Class Driver + * + * \section Sec_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) + * + * \section Sec_ModDescription Module Description + * Android Open Accessory Class Driver module. This module contains an internal implementation of the USB Android Open Accessory + * Class, for Host USB mode. User applications can use this class driver instead of implementing the Android Open Accessory Class + * manually via the low-level LUFA APIs. + * + * This module is designed to simplify the user code by exposing only the required interface needed to interface with + * Host using the USB Android Open Accessory Class. + * + * @{ + */ + +#ifndef _AOA_CLASS_H_ +#define _AOA_CLASS_H_ + + /* Macros: */ + #define __INCLUDE_FROM_USB_DRIVER + #define __INCLUDE_FROM_AOA_DRIVER + + /* Includes: */ + #include "../Core/USBMode.h" + + #if defined(USB_CAN_BE_HOST) + #include "Host/AndroidAccessoryClassHost.h" + #endif + +#endif + +/** @} */ + diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Common/AndroidAccessoryClassCommon.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Common/AndroidAccessoryClassCommon.h index c1c0e8df0..dc1289da6 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Common/AndroidAccessoryClassCommon.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Common/AndroidAccessoryClassCommon.h @@ -1,128 +1,128 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Common definitions and declarations for the library USB Android Open Accessory Class driver. - * - * Common definitions and declarations for the library USB Android Open Accessory Class driver. - * - * \note This file should not be included directly. It is automatically included as needed by the USB module driver - * dispatch header located in LUFA/Drivers/USB.h. - */ - -/** \ingroup Group_USBClassAOA - * \defgroup Group_USBClassAOACommon Common Class Definitions - * - * \section Sec_ModDescription Module Description - * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB - * Android Open Accessory Class. - * - * @{ - */ - -#ifndef _AOA_CLASS_COMMON_H_ -#define _AOA_CLASS_COMMON_H_ - - /* Includes: */ - #include "../../Core/StdDescriptors.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_AOA_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. - #endif - - /* Macros: */ - /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory mode. */ - #define ANDROID_ACCESSORY_PRODUCT_ID 0x2D00 - - /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory and Android Debug mode. */ - #define ANDROID_ACCESSORY_ADB_PRODUCT_ID 0x2D01 - - /* Enums: */ - /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the - * Android Open Accessory class. - */ - enum AOA_Descriptor_ClassSubclassProtocol_t - { - AOA_CSCP_AOADataClass = 0xFF, /**< Descriptor Class value indicating that the device or interface - * belongs to the AOA data class. - */ - AOA_CSCP_AOADataSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device or interface - * belongs to AOA data subclass. - */ - AOA_CSCP_AOADataProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface - * belongs to the AOA data class protocol. - */ - }; - - /** Enum for the Android Open Accessory class specific control requests that can be issued by the USB bus host. */ - enum AOA_ClassRequests_t - { - AOA_REQ_GetAccessoryProtocol = 0x33, /**< Android Open Accessory control request to retrieve the device's supported Accessory Protocol version. */ - AOA_REQ_SendString = 0x34, /**< Android Open Accessory control request to set an accessory property string in the device. */ - AOA_REQ_StartAccessoryMode = 0x35, /**< Android Open Accessory control request to switch the device into Accessory mode. */ - }; - - /** Enum for the possible Android Open Accessory property string indexes. */ - enum AOA_Strings_t - { - AOA_STRING_Manufacturer = 0, /**< Index of the Manufacturer property string. */ - AOA_STRING_Model = 1, /**< Index of the Model Name property string. */ - AOA_STRING_Description = 2, /**< Index of the Description property string. */ - AOA_STRING_Version = 3, /**< Index of the Version Number property string. */ - AOA_STRING_URI = 4, /**< Index of the URI Information property string. */ - AOA_STRING_Serial = 5, /**< Index of the Serial Number property string. */ - - #if !defined(__DOXYGEN__) - AOA_STRING_TOTAL_STRINGS - #endif - }; - - /** Enum for the possible Android Open Accessory protocol versions. */ - enum AOA_Protocols_t - { - AOA_PROTOCOL_AccessoryV1 = 0x0001, /**< Android Open Accessory version 1. */ - }; - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Common definitions and declarations for the library USB Android Open Accessory Class driver. + * + * Common definitions and declarations for the library USB Android Open Accessory Class driver. + * + * \note This file should not be included directly. It is automatically included as needed by the USB module driver + * dispatch header located in LUFA/Drivers/USB.h. + */ + +/** \ingroup Group_USBClassAOA + * \defgroup Group_USBClassAOACommon Common Class Definitions + * + * \section Sec_ModDescription Module Description + * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB + * Android Open Accessory Class. + * + * @{ + */ + +#ifndef _AOA_CLASS_COMMON_H_ +#define _AOA_CLASS_COMMON_H_ + + /* Includes: */ + #include "../../Core/StdDescriptors.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_AOA_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #endif + + /* Macros: */ + /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory mode. */ + #define ANDROID_ACCESSORY_PRODUCT_ID 0x2D00 + + /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory and Android Debug mode. */ + #define ANDROID_ACCESSORY_ADB_PRODUCT_ID 0x2D01 + + /* Enums: */ + /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the + * Android Open Accessory class. + */ + enum AOA_Descriptor_ClassSubclassProtocol_t + { + AOA_CSCP_AOADataClass = 0xFF, /**< Descriptor Class value indicating that the device or interface + * belongs to the AOA data class. + */ + AOA_CSCP_AOADataSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device or interface + * belongs to AOA data subclass. + */ + AOA_CSCP_AOADataProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface + * belongs to the AOA data class protocol. + */ + }; + + /** Enum for the Android Open Accessory class specific control requests that can be issued by the USB bus host. */ + enum AOA_ClassRequests_t + { + AOA_REQ_GetAccessoryProtocol = 0x33, /**< Android Open Accessory control request to retrieve the device's supported Accessory Protocol version. */ + AOA_REQ_SendString = 0x34, /**< Android Open Accessory control request to set an accessory property string in the device. */ + AOA_REQ_StartAccessoryMode = 0x35, /**< Android Open Accessory control request to switch the device into Accessory mode. */ + }; + + /** Enum for the possible Android Open Accessory property string indexes. */ + enum AOA_Strings_t + { + AOA_STRING_Manufacturer = 0, /**< Index of the Manufacturer property string. */ + AOA_STRING_Model = 1, /**< Index of the Model Name property string. */ + AOA_STRING_Description = 2, /**< Index of the Description property string. */ + AOA_STRING_Version = 3, /**< Index of the Version Number property string. */ + AOA_STRING_URI = 4, /**< Index of the URI Information property string. */ + AOA_STRING_Serial = 5, /**< Index of the Serial Number property string. */ + + #if !defined(__DOXYGEN__) + AOA_STRING_TOTAL_STRINGS + #endif + }; + + /** Enum for the possible Android Open Accessory protocol versions. */ + enum AOA_Protocols_t + { + AOA_PROTOCOL_AccessoryV1 = 0x0001, /**< Android Open Accessory version 1. */ + }; + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c index 7c564e012..f71fa2b95 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c @@ -1,422 +1,422 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#define __INCLUDE_FROM_USB_DRIVER -#include "../../Core/USBMode.h" - -#if defined(USB_CAN_BE_HOST) - -#define __INCLUDE_FROM_AOA_DRIVER -#define __INCLUDE_FROM_ANDROIDACCESSORY_HOST_C -#include "AndroidAccessoryClassHost.h" - -bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const USB_Descriptor_Device_t* const DeviceDescriptor, - bool* const NeedModeSwitch) -{ - (void)AOAInterfaceInfo; - - if (DeviceDescriptor->Header.Type != DTYPE_Device) - return false; - - *NeedModeSwitch = ((DeviceDescriptor->ProductID != ANDROID_ACCESSORY_PRODUCT_ID) && - (DeviceDescriptor->ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID)); - - return true; -} - -uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - uint16_t ConfigDescriptorSize, - void* ConfigDescriptorData) -{ - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; - USB_Descriptor_Interface_t* AOAInterface = NULL; - - memset(&AOAInterfaceInfo->State, 0x00, sizeof(AOAInterfaceInfo->State)); - - if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration) - return AOA_ENUMERROR_InvalidConfigDescriptor; - - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - DCOMP_AOA_Host_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - return AOA_ENUMERROR_NoCompatibleInterfaceFound; - } - - AOAInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t); - - while (!(DataINEndpoint) || !(DataOUTEndpoint)) - { - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - DCOMP_AOA_Host_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) - { - return AOA_ENUMERROR_NoCompatibleInterfaceFound; - } - - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); - - if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN) - DataINEndpoint = EndpointData; - else - DataOUTEndpoint = EndpointData; - } - - AOAInterfaceInfo->Config.DataINPipe.Size = le16_to_cpu(DataINEndpoint->EndpointSize); - AOAInterfaceInfo->Config.DataINPipe.EndpointAddress = DataINEndpoint->EndpointAddress; - AOAInterfaceInfo->Config.DataINPipe.Type = EP_TYPE_BULK; - - AOAInterfaceInfo->Config.DataOUTPipe.Size = le16_to_cpu(DataOUTEndpoint->EndpointSize); - AOAInterfaceInfo->Config.DataOUTPipe.EndpointAddress = DataOUTEndpoint->EndpointAddress; - AOAInterfaceInfo->Config.DataOUTPipe.Type = EP_TYPE_BULK; - - if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataINPipe, 1))) - return false; - - if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataOUTPipe, 1))) - return false; - - AOAInterfaceInfo->State.IsActive = true; - AOAInterfaceInfo->State.InterfaceNumber = AOAInterface->InterfaceNumber; - - return AOA_ENUMERROR_NoError; -} - -static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor) -{ - USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); - - if (Header->Type == DTYPE_Interface) - { - USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t); - - if ((Interface->Class == AOA_CSCP_AOADataClass) && - (Interface->SubClass == AOA_CSCP_AOADataSubclass) && - (Interface->Protocol == AOA_CSCP_AOADataProtocol)) - { - return DESCRIPTOR_SEARCH_Found; - } - } - - return DESCRIPTOR_SEARCH_NotFound; -} - -static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) -{ - USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); - - if (Header->Type == DTYPE_Endpoint) - { - USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t); - - uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK); - - if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress)))) - return DESCRIPTOR_SEARCH_Found; - } - else if (Header->Type == DTYPE_Interface) - { - return DESCRIPTOR_SEARCH_Fail; - } - - return DESCRIPTOR_SEARCH_NotFound; -} - -void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return; - - #if !defined(NO_CLASS_DRIVER_AUTOFLUSH) - AOA_Host_Flush(AOAInterfaceInfo); - #endif -} - -uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - uint8_t ErrorCode; - - uint16_t AccessoryProtocol; - if ((ErrorCode = AOA_Host_GetAccessoryProtocol(&AccessoryProtocol)) != HOST_WAITERROR_Successful) - return ErrorCode; - - if (AccessoryProtocol != CPU_TO_LE16(AOA_PROTOCOL_AccessoryV1)) - return AOA_ERROR_LOGICAL_CMD_FAILED; - - for (uint8_t PropertyIndex = 0; PropertyIndex < AOA_STRING_TOTAL_STRINGS; PropertyIndex++) - { - if ((ErrorCode = AOA_Host_SendPropertyString(AOAInterfaceInfo, PropertyIndex)) != HOST_WAITERROR_Successful) - return ErrorCode; - } - - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE), - .bRequest = AOA_REQ_StartAccessoryMode, - .wValue = 0, - .wIndex = 0, - .wLength = 0, - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - return USB_Host_SendControlRequest(NULL); -} - -static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) -{ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE), - .bRequest = AOA_REQ_GetAccessoryProtocol, - .wValue = 0, - .wIndex = 0, - .wLength = sizeof(uint16_t), - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - return USB_Host_SendControlRequest(Protocol); -} - -static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t StringIndex) -{ - const char* String = AOAInterfaceInfo->Config.PropertyStrings[StringIndex]; - - if (String == NULL) - String = ""; - - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE), - .bRequest = AOA_REQ_SendString, - .wValue = 0, - .wIndex = StringIndex, - .wLength = (strlen(String) + 1), - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - return USB_Host_SendControlRequest((char*)String); -} - -uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t* const Buffer, - const uint16_t Length) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return PIPE_READYWAIT_DeviceDisconnected; - - uint8_t ErrorCode; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); - - Pipe_Unfreeze(); - ErrorCode = Pipe_Write_Stream_LE(Buffer, Length, NULL); - Pipe_Freeze(); - - return ErrorCode; -} - -uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const char* const String) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return PIPE_READYWAIT_DeviceDisconnected; - - uint8_t ErrorCode; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); - - Pipe_Unfreeze(); - ErrorCode = Pipe_Write_Stream_LE(String, strlen(String), NULL); - Pipe_Freeze(); - - return ErrorCode; -} - -uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t Data) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return PIPE_READYWAIT_DeviceDisconnected; - - uint8_t ErrorCode; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); - Pipe_Unfreeze(); - - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearOUT(); - - if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) - return ErrorCode; - } - - Pipe_Write_8(Data); - Pipe_Freeze(); - - return PIPE_READYWAIT_NoError; -} - -uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return 0; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address); - Pipe_Unfreeze(); - - if (Pipe_IsINReceived()) - { - if (!(Pipe_BytesInPipe())) - { - Pipe_ClearIN(); - Pipe_Freeze(); - return 0; - } - else - { - Pipe_Freeze(); - return Pipe_BytesInPipe(); - } - } - else - { - Pipe_Freeze(); - - return 0; - } -} - -int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return -1; - - int16_t ReceivedByte = -1; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address); - Pipe_Unfreeze(); - - if (Pipe_IsINReceived()) - { - if (Pipe_BytesInPipe()) - ReceivedByte = Pipe_Read_8(); - - if (!(Pipe_BytesInPipe())) - Pipe_ClearIN(); - } - - Pipe_Freeze(); - - return ReceivedByte; -} - -uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return PIPE_READYWAIT_DeviceDisconnected; - - uint8_t ErrorCode; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); - Pipe_Unfreeze(); - - if (!(Pipe_BytesInPipe())) - return PIPE_READYWAIT_NoError; - - bool BankFull = !(Pipe_IsReadWriteAllowed()); - - Pipe_ClearOUT(); - - if (BankFull) - { - if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) - return ErrorCode; - - Pipe_ClearOUT(); - } - - Pipe_Freeze(); - - return PIPE_READYWAIT_NoError; -} - -#if defined(FDEV_SETUP_STREAM) -void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - FILE* const Stream) -{ - *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar, _FDEV_SETUP_RW); - fdev_set_udata(Stream, AOAInterfaceInfo); -} - -void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - FILE* const Stream) -{ - *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar_Blocking, _FDEV_SETUP_RW); - fdev_set_udata(Stream, AOAInterfaceInfo); -} - -static int AOA_Host_putchar(char c, - FILE* Stream) -{ - return AOA_Host_SendByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0; -} - -static int AOA_Host_getchar(FILE* Stream) -{ - int16_t ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); - - if (ReceivedByte < 0) - return _FDEV_EOF; - - return ReceivedByte; -} - -static int AOA_Host_getchar_Blocking(FILE* Stream) -{ - int16_t ReceivedByte; - - while ((ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream))) < 0) - { - if (USB_HostState == HOST_STATE_Unattached) - return _FDEV_EOF; - - AOA_Host_USBTask((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); - USB_USBTask(); - } - - return ReceivedByte; -} -#endif - -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#define __INCLUDE_FROM_USB_DRIVER +#include "../../Core/USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#define __INCLUDE_FROM_AOA_DRIVER +#define __INCLUDE_FROM_ANDROIDACCESSORY_HOST_C +#include "AndroidAccessoryClassHost.h" + +bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const USB_Descriptor_Device_t* const DeviceDescriptor, + bool* const NeedModeSwitch) +{ + (void)AOAInterfaceInfo; + + if (DeviceDescriptor->Header.Type != DTYPE_Device) + return false; + + *NeedModeSwitch = ((DeviceDescriptor->ProductID != ANDROID_ACCESSORY_PRODUCT_ID) && + (DeviceDescriptor->ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID)); + + return true; +} + +uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + uint16_t ConfigDescriptorSize, + void* ConfigDescriptorData) +{ + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Interface_t* AOAInterface = NULL; + + memset(&AOAInterfaceInfo->State, 0x00, sizeof(AOAInterfaceInfo->State)); + + if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration) + return AOA_ENUMERROR_InvalidConfigDescriptor; + + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + DCOMP_AOA_Host_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + return AOA_ENUMERROR_NoCompatibleInterfaceFound; + } + + AOAInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t); + + while (!(DataINEndpoint) || !(DataOUTEndpoint)) + { + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + DCOMP_AOA_Host_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + { + return AOA_ENUMERROR_NoCompatibleInterfaceFound; + } + + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); + + if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN) + DataINEndpoint = EndpointData; + else + DataOUTEndpoint = EndpointData; + } + + AOAInterfaceInfo->Config.DataINPipe.Size = le16_to_cpu(DataINEndpoint->EndpointSize); + AOAInterfaceInfo->Config.DataINPipe.EndpointAddress = DataINEndpoint->EndpointAddress; + AOAInterfaceInfo->Config.DataINPipe.Type = EP_TYPE_BULK; + + AOAInterfaceInfo->Config.DataOUTPipe.Size = le16_to_cpu(DataOUTEndpoint->EndpointSize); + AOAInterfaceInfo->Config.DataOUTPipe.EndpointAddress = DataOUTEndpoint->EndpointAddress; + AOAInterfaceInfo->Config.DataOUTPipe.Type = EP_TYPE_BULK; + + if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataINPipe, 1))) + return false; + + if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataOUTPipe, 1))) + return false; + + AOAInterfaceInfo->State.IsActive = true; + AOAInterfaceInfo->State.InterfaceNumber = AOAInterface->InterfaceNumber; + + return AOA_ENUMERROR_NoError; +} + +static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor) +{ + USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); + + if (Header->Type == DTYPE_Interface) + { + USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t); + + if ((Interface->Class == AOA_CSCP_AOADataClass) && + (Interface->SubClass == AOA_CSCP_AOADataSubclass) && + (Interface->Protocol == AOA_CSCP_AOADataProtocol)) + { + return DESCRIPTOR_SEARCH_Found; + } + } + + return DESCRIPTOR_SEARCH_NotFound; +} + +static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) +{ + USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); + + if (Header->Type == DTYPE_Endpoint) + { + USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t); + + uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK); + + if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress)))) + return DESCRIPTOR_SEARCH_Found; + } + else if (Header->Type == DTYPE_Interface) + { + return DESCRIPTOR_SEARCH_Fail; + } + + return DESCRIPTOR_SEARCH_NotFound; +} + +void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return; + + #if !defined(NO_CLASS_DRIVER_AUTOFLUSH) + AOA_Host_Flush(AOAInterfaceInfo); + #endif +} + +uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + uint8_t ErrorCode; + + uint16_t AccessoryProtocol; + if ((ErrorCode = AOA_Host_GetAccessoryProtocol(&AccessoryProtocol)) != HOST_WAITERROR_Successful) + return ErrorCode; + + if (AccessoryProtocol != CPU_TO_LE16(AOA_PROTOCOL_AccessoryV1)) + return AOA_ERROR_LOGICAL_CMD_FAILED; + + for (uint8_t PropertyIndex = 0; PropertyIndex < AOA_STRING_TOTAL_STRINGS; PropertyIndex++) + { + if ((ErrorCode = AOA_Host_SendPropertyString(AOAInterfaceInfo, PropertyIndex)) != HOST_WAITERROR_Successful) + return ErrorCode; + } + + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE), + .bRequest = AOA_REQ_StartAccessoryMode, + .wValue = 0, + .wIndex = 0, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + return USB_Host_SendControlRequest(NULL); +} + +static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE), + .bRequest = AOA_REQ_GetAccessoryProtocol, + .wValue = 0, + .wIndex = 0, + .wLength = sizeof(uint16_t), + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + return USB_Host_SendControlRequest(Protocol); +} + +static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t StringIndex) +{ + const char* String = AOAInterfaceInfo->Config.PropertyStrings[StringIndex]; + + if (String == NULL) + String = ""; + + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE), + .bRequest = AOA_REQ_SendString, + .wValue = 0, + .wIndex = StringIndex, + .wLength = (strlen(String) + 1), + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + return USB_Host_SendControlRequest((char*)String); +} + +uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t* const Buffer, + const uint16_t Length) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return PIPE_READYWAIT_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); + + Pipe_Unfreeze(); + ErrorCode = Pipe_Write_Stream_LE(Buffer, Length, NULL); + Pipe_Freeze(); + + return ErrorCode; +} + +uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const char* const String) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return PIPE_READYWAIT_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); + + Pipe_Unfreeze(); + ErrorCode = Pipe_Write_Stream_LE(String, strlen(String), NULL); + Pipe_Freeze(); + + return ErrorCode; +} + +uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t Data) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return PIPE_READYWAIT_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); + Pipe_Unfreeze(); + + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearOUT(); + + if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) + return ErrorCode; + } + + Pipe_Write_8(Data); + Pipe_Freeze(); + + return PIPE_READYWAIT_NoError; +} + +uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return 0; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address); + Pipe_Unfreeze(); + + if (Pipe_IsINReceived()) + { + if (!(Pipe_BytesInPipe())) + { + Pipe_ClearIN(); + Pipe_Freeze(); + return 0; + } + else + { + Pipe_Freeze(); + return Pipe_BytesInPipe(); + } + } + else + { + Pipe_Freeze(); + + return 0; + } +} + +int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return -1; + + int16_t ReceivedByte = -1; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address); + Pipe_Unfreeze(); + + if (Pipe_IsINReceived()) + { + if (Pipe_BytesInPipe()) + ReceivedByte = Pipe_Read_8(); + + if (!(Pipe_BytesInPipe())) + Pipe_ClearIN(); + } + + Pipe_Freeze(); + + return ReceivedByte; +} + +uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return PIPE_READYWAIT_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); + Pipe_Unfreeze(); + + if (!(Pipe_BytesInPipe())) + return PIPE_READYWAIT_NoError; + + bool BankFull = !(Pipe_IsReadWriteAllowed()); + + Pipe_ClearOUT(); + + if (BankFull) + { + if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) + return ErrorCode; + + Pipe_ClearOUT(); + } + + Pipe_Freeze(); + + return PIPE_READYWAIT_NoError; +} + +#if defined(FDEV_SETUP_STREAM) +void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + FILE* const Stream) +{ + *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar, _FDEV_SETUP_RW); + fdev_set_udata(Stream, AOAInterfaceInfo); +} + +void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + FILE* const Stream) +{ + *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar_Blocking, _FDEV_SETUP_RW); + fdev_set_udata(Stream, AOAInterfaceInfo); +} + +static int AOA_Host_putchar(char c, + FILE* Stream) +{ + return AOA_Host_SendByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0; +} + +static int AOA_Host_getchar(FILE* Stream) +{ + int16_t ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); + + if (ReceivedByte < 0) + return _FDEV_EOF; + + return ReceivedByte; +} + +static int AOA_Host_getchar_Blocking(FILE* Stream) +{ + int16_t ReceivedByte; + + while ((ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream))) < 0) + { + if (USB_HostState == HOST_STATE_Unattached) + return _FDEV_EOF; + + AOA_Host_USBTask((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); + USB_USBTask(); + } + + return ReceivedByte; +} +#endif + +#endif + diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.h index f55cd340a..c437a4b61 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.h @@ -1,314 +1,314 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Host mode driver for the library USB Android Open Accessory Class driver. - * - * Host mode driver for the library USB Android Open Accessory Class driver. - * - * \note This file should not be included directly. It is automatically included as needed by the USB module driver - * dispatch header located in LUFA/Drivers/USB.h. - */ - -/** \ingroup Group_USBClassAOA - * \defgroup Group_USBClassAndroidAccessoryHost Android Open Accessory Class Host Mode Driver - * - * \section Sec_Dependencies Module Source Dependencies - * The following files must be built with any user project that uses this module: - * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) - * - * \section Sec_ModDescription Module Description - * Host Mode USB Class driver framework interface, for the Android Open Accessory USB Class driver. - * - * @{ - */ - -#ifndef __AOA_CLASS_HOST_H__ -#define __AOA_CLASS_HOST_H__ - - /* Includes: */ - #include "../../USB.h" - #include "../Common/AndroidAccessoryClassCommon.h" - - #include - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_AOA_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Error code for some Android Open Accessory Host functions, indicating a logical (and not hardware) error. */ - #define AOA_ERROR_LOGICAL_CMD_FAILED 0x80 - - /* Type Defines: */ - /** \brief Android Open Accessory Class Host Mode Configuration and State Structure. - * - * Class state structure. An instance of this structure should be made within the user application, - * and passed to each of the Android Open Accessory class driver functions as the \c AOAInterfaceInfo - * parameter. This stores each Android Open Accessory interface's configuration and state information. - */ - typedef struct - { - struct - { - USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */ - USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */ - - char* PropertyStrings[AOA_STRING_TOTAL_STRINGS]; /**< Android Accessory property strings, sent to identify the accessory when the - * Android device is switched into Open Accessory mode. */ - } Config; /**< Config data for the USB class interface within the device. All elements in this section - * must be set or the interface will fail to enumerate and operate correctly. - */ - struct - { - bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid - * after \ref AOA_Host_ConfigurePipes() is called and the Host state machine is in the - * Configured state. - */ - uint8_t InterfaceNumber; /**< Interface index of the AOA interface within the attached device. */ - } State; /**< State data for the USB class interface within the device. All elements in this section - * may be set to initial values, but may also be ignored to default to sane values when - * the interface is enumerated. - */ - } USB_ClassInfo_AOA_Host_t; - - /* Enums: */ - /** Enum for the possible error codes returned by the \ref AOA_Host_ConfigurePipes() function. */ - enum AOA_Host_EnumerationFailure_ErrorCodes_t - { - AOA_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */ - AOA_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */ - AOA_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible Android Open Accessory interface was not found in the device's Configuration Descriptor. */ - AOA_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */ - }; - - /* Function Prototypes: */ - /** General management task for a given Android Open Accessory host class interface, required for the correct operation of the interface. - * This should be called frequently in the main program loop, before the master USB management task \ref USB_USBTask(). - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an Android Open Accessory Class host configuration and state. - */ - void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Validates a device descriptor, to check if the device is a valid Android device, and if it is currently in Android Open Accessory mode. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. - * \param[in] DeviceDescriptor Pointer a buffer containing the attached device's Device Descriptor. - * \param[out] NeedModeSwitch Pointer to a boolean where the mode switch requirement of the attached device is to be stored. - * - * \return Boolean \c true if the attached device is a valid Android device, \c false otherwise. - */ - bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const USB_Descriptor_Device_t* const DeviceDescriptor, - bool* const NeedModeSwitch) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3); - - /** Host interface configuration routine, to configure a given Android Open Accessory host interface instance using the Configuration - * Descriptor read from an attached USB device. This function automatically updates the given Android Open Accessory Host instance's - * state values and configures the pipes required to communicate with the interface if it is found within the device. This should be - * called once after the stack has enumerated the attached device, while the host state machine is in the Addressed state. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. - * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor. - * \param[in] ConfigDescriptorData Pointer to a buffer containing the attached device's Configuration Descriptor. - * - * \return A value from the \ref AOA_Host_EnumerationFailure_ErrorCodes_t enum. - */ - uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - uint16_t ConfigDescriptorSize, - void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3); - - /** Starts Accessory Mode in the attached Android device. This function will validate the device's Android Open Accessory protocol - * version, send the configured property strings, and request a switch to Android Open Accessory mode. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. - * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum, or \ref AOA_ERROR_LOGICAL_CMD_FAILED if a logical error occurred.. - */ - uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Sends a given data buffer to the attached USB device, if connected. If a device is not connected when the function is - * called, the data will be discarded. Bytes will be queued for transmission to the device until either the pipe bank - * becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows for - * multiple bytes to be packed into a single pipe packet, increasing data throughput. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * \param[in] Buffer Pointer to a buffer containing the data to send to the device. - * \param[in] Length Length of the data to send to the device. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t* const Buffer, - const uint16_t Length); - - /** Sends a given null-terminated string to the attached USB device, if connected. If a device is not connected when the - * function is called, the string is discarded. Bytes will be queued for transmission to the device until either the pipe - * bank becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows - * for multiple bytes to be packed into a single pipe packet, increasing data throughput. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * \param[in] String Pointer to the null terminated string to send to the device. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const char* const String) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2); - - /** Sends a given byte to the attached USB device, if connected. If a device is not connected when the function is called, the - * byte is discarded. Bytes will be queued for transmission to the device until either the pipe bank becomes full, or the - * \ref AOA_Host_Flush() function is called to flush the pending data to the host. This allows for multiple bytes to be - * packed into a single pipe packet, increasing data throughput. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * \param[in] Data Byte of data to send to the device. - * - * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. - */ - uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1); - - /** Determines the number of bytes received by the AOA interface from the device, waiting to be read. This indicates the number - * of bytes in the IN pipe bank only, and thus the number of calls to \ref AOA_Host_ReceiveByte() which are guaranteed to succeed - * immediately. If multiple bytes are to be received, they should be buffered by the user application, as the pipe bank will not be - * released back to the USB controller until all bytes are read. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * - * \return Total number of buffered bytes received from the device. - */ - uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Reads a byte of data from the device. If no data is waiting to be read of if a USB device is not connected, the function - * returns a negative value. The \ref AOA_Host_BytesReceived() function may be queried in advance to determine how many bytes - * are currently buffered in the AOA interface's data receive pipe. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * - * \return Next received byte from the device, or a negative value if no data received. - */ - int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Flushes any data waiting to be sent, ensuring that the send buffer is cleared. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * - * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. - */ - uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Creates a standard character stream for the given AOA Device instance so that it can be used with all the regular - * functions in the standard \c library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created - * stream is bidirectional and can be used for both input and output functions. - * - * Reading data from this stream is non-blocking, i.e. in most instances, complete strings cannot be read in by a single - * fetch, as the endpoint will not be ready at some point in the transmission, aborting the transfer. However, this may - * be used when the read data is processed byte-per-bye (via \c getc()) or when the user application will implement its own - * line buffering. - * - * \note The created stream can be given as \c stdout if desired to direct the standard output from all \c functions - * to the given AOA interface. - * \n\n - * - * \note This function is not available on all microcontroller architectures. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state. - * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. - */ - void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - FILE* const Stream); - - /** Identical to \ref AOA_Host_CreateStream(), except that reads are blocking until the calling stream function terminates - * the transfer. While blocking, the USB and AOA service tasks are called repeatedly to maintain USB communications. - * - * \note This function is not available on all microcontroller architectures. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state. - * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. - */ - void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - FILE* const Stream); - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - /* Function Prototypes: */ - #if defined(__INCLUDE_FROM_ANDROIDACCESSORY_HOST_C) - #if defined(FDEV_SETUP_STREAM) - static int AOA_Host_putchar(char c, - FILE* Stream) ATTR_NON_NULL_PTR_ARG(2); - static int AOA_Host_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); - static int AOA_Host_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); - #endif - - static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) ATTR_NON_NULL_PTR_ARG(1); - static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t StringIndex) ATTR_NON_NULL_PTR_ARG(1); - - static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor) - ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1); - static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) - ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1); - #endif - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Host mode driver for the library USB Android Open Accessory Class driver. + * + * Host mode driver for the library USB Android Open Accessory Class driver. + * + * \note This file should not be included directly. It is automatically included as needed by the USB module driver + * dispatch header located in LUFA/Drivers/USB.h. + */ + +/** \ingroup Group_USBClassAOA + * \defgroup Group_USBClassAndroidAccessoryHost Android Open Accessory Class Host Mode Driver + * + * \section Sec_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) + * + * \section Sec_ModDescription Module Description + * Host Mode USB Class driver framework interface, for the Android Open Accessory USB Class driver. + * + * @{ + */ + +#ifndef __AOA_CLASS_HOST_H__ +#define __AOA_CLASS_HOST_H__ + + /* Includes: */ + #include "../../USB.h" + #include "../Common/AndroidAccessoryClassCommon.h" + + #include + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_AOA_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Error code for some Android Open Accessory Host functions, indicating a logical (and not hardware) error. */ + #define AOA_ERROR_LOGICAL_CMD_FAILED 0x80 + + /* Type Defines: */ + /** \brief Android Open Accessory Class Host Mode Configuration and State Structure. + * + * Class state structure. An instance of this structure should be made within the user application, + * and passed to each of the Android Open Accessory class driver functions as the \c AOAInterfaceInfo + * parameter. This stores each Android Open Accessory interface's configuration and state information. + */ + typedef struct + { + struct + { + USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */ + USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */ + + char* PropertyStrings[AOA_STRING_TOTAL_STRINGS]; /**< Android Accessory property strings, sent to identify the accessory when the + * Android device is switched into Open Accessory mode. */ + } Config; /**< Config data for the USB class interface within the device. All elements in this section + * must be set or the interface will fail to enumerate and operate correctly. + */ + struct + { + bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid + * after \ref AOA_Host_ConfigurePipes() is called and the Host state machine is in the + * Configured state. + */ + uint8_t InterfaceNumber; /**< Interface index of the AOA interface within the attached device. */ + } State; /**< State data for the USB class interface within the device. All elements in this section + * may be set to initial values, but may also be ignored to default to sane values when + * the interface is enumerated. + */ + } USB_ClassInfo_AOA_Host_t; + + /* Enums: */ + /** Enum for the possible error codes returned by the \ref AOA_Host_ConfigurePipes() function. */ + enum AOA_Host_EnumerationFailure_ErrorCodes_t + { + AOA_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */ + AOA_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */ + AOA_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible Android Open Accessory interface was not found in the device's Configuration Descriptor. */ + AOA_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */ + }; + + /* Function Prototypes: */ + /** General management task for a given Android Open Accessory host class interface, required for the correct operation of the interface. + * This should be called frequently in the main program loop, before the master USB management task \ref USB_USBTask(). + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an Android Open Accessory Class host configuration and state. + */ + void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Validates a device descriptor, to check if the device is a valid Android device, and if it is currently in Android Open Accessory mode. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. + * \param[in] DeviceDescriptor Pointer a buffer containing the attached device's Device Descriptor. + * \param[out] NeedModeSwitch Pointer to a boolean where the mode switch requirement of the attached device is to be stored. + * + * \return Boolean \c true if the attached device is a valid Android device, \c false otherwise. + */ + bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const USB_Descriptor_Device_t* const DeviceDescriptor, + bool* const NeedModeSwitch) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3); + + /** Host interface configuration routine, to configure a given Android Open Accessory host interface instance using the Configuration + * Descriptor read from an attached USB device. This function automatically updates the given Android Open Accessory Host instance's + * state values and configures the pipes required to communicate with the interface if it is found within the device. This should be + * called once after the stack has enumerated the attached device, while the host state machine is in the Addressed state. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. + * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor. + * \param[in] ConfigDescriptorData Pointer to a buffer containing the attached device's Configuration Descriptor. + * + * \return A value from the \ref AOA_Host_EnumerationFailure_ErrorCodes_t enum. + */ + uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + uint16_t ConfigDescriptorSize, + void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3); + + /** Starts Accessory Mode in the attached Android device. This function will validate the device's Android Open Accessory protocol + * version, send the configured property strings, and request a switch to Android Open Accessory mode. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum, or \ref AOA_ERROR_LOGICAL_CMD_FAILED if a logical error occurred.. + */ + uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Sends a given data buffer to the attached USB device, if connected. If a device is not connected when the function is + * called, the data will be discarded. Bytes will be queued for transmission to the device until either the pipe bank + * becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows for + * multiple bytes to be packed into a single pipe packet, increasing data throughput. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * \param[in] Buffer Pointer to a buffer containing the data to send to the device. + * \param[in] Length Length of the data to send to the device. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t* const Buffer, + const uint16_t Length); + + /** Sends a given null-terminated string to the attached USB device, if connected. If a device is not connected when the + * function is called, the string is discarded. Bytes will be queued for transmission to the device until either the pipe + * bank becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows + * for multiple bytes to be packed into a single pipe packet, increasing data throughput. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * \param[in] String Pointer to the null terminated string to send to the device. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const char* const String) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2); + + /** Sends a given byte to the attached USB device, if connected. If a device is not connected when the function is called, the + * byte is discarded. Bytes will be queued for transmission to the device until either the pipe bank becomes full, or the + * \ref AOA_Host_Flush() function is called to flush the pending data to the host. This allows for multiple bytes to be + * packed into a single pipe packet, increasing data throughput. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * \param[in] Data Byte of data to send to the device. + * + * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. + */ + uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1); + + /** Determines the number of bytes received by the AOA interface from the device, waiting to be read. This indicates the number + * of bytes in the IN pipe bank only, and thus the number of calls to \ref AOA_Host_ReceiveByte() which are guaranteed to succeed + * immediately. If multiple bytes are to be received, they should be buffered by the user application, as the pipe bank will not be + * released back to the USB controller until all bytes are read. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * + * \return Total number of buffered bytes received from the device. + */ + uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads a byte of data from the device. If no data is waiting to be read of if a USB device is not connected, the function + * returns a negative value. The \ref AOA_Host_BytesReceived() function may be queried in advance to determine how many bytes + * are currently buffered in the AOA interface's data receive pipe. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * + * \return Next received byte from the device, or a negative value if no data received. + */ + int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Flushes any data waiting to be sent, ensuring that the send buffer is cleared. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * + * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. + */ + uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Creates a standard character stream for the given AOA Device instance so that it can be used with all the regular + * functions in the standard \c library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created + * stream is bidirectional and can be used for both input and output functions. + * + * Reading data from this stream is non-blocking, i.e. in most instances, complete strings cannot be read in by a single + * fetch, as the endpoint will not be ready at some point in the transmission, aborting the transfer. However, this may + * be used when the read data is processed byte-per-bye (via \c getc()) or when the user application will implement its own + * line buffering. + * + * \note The created stream can be given as \c stdout if desired to direct the standard output from all \c functions + * to the given AOA interface. + * \n\n + * + * \note This function is not available on all microcontroller architectures. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state. + * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. + */ + void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + FILE* const Stream); + + /** Identical to \ref AOA_Host_CreateStream(), except that reads are blocking until the calling stream function terminates + * the transfer. While blocking, the USB and AOA service tasks are called repeatedly to maintain USB communications. + * + * \note This function is not available on all microcontroller architectures. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state. + * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. + */ + void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + FILE* const Stream); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Function Prototypes: */ + #if defined(__INCLUDE_FROM_ANDROIDACCESSORY_HOST_C) + #if defined(FDEV_SETUP_STREAM) + static int AOA_Host_putchar(char c, + FILE* Stream) ATTR_NON_NULL_PTR_ARG(2); + static int AOA_Host_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); + static int AOA_Host_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); + #endif + + static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) ATTR_NON_NULL_PTR_ARG(1); + static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t StringIndex) ATTR_NON_NULL_PTR_ARG(1); + + static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1); + static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1); + #endif + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + + diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c index 0117a1d66..a267be1ee 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c @@ -1,275 +1,275 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#include "../../../../Common/Common.h" -#if (ARCH == ARCH_AVR8) - -#define __INCLUDE_FROM_USB_DRIVER -#include "../USBMode.h" - -#if defined(USB_CAN_BE_DEVICE) - -#include "EndpointStream_AVR8.h" - -#if !defined(CONTROL_ONLY_DEVICE) -uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Discard_8(); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Write_8(0); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, - * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" -#endif - -#endif - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_Control_R.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_Control_R.c" -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVR8) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "EndpointStream_AVR8.h" + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Discard_8(); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Write_8(0); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, + * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" #endif -#endif +#endif + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_Control_R.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_Control_R.c" +#endif + +#endif + +#endif diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h index 072d85932..2d98ef4d6 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h @@ -1,648 +1,648 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Endpoint data stream transmission and reception management for the AVR8 microcontrollers. - * \copydetails Group_EndpointStreamRW_AVR8 - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_EndpointStreamRW - * \defgroup Group_EndpointStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8) - * \brief Endpoint data stream transmission and reception management for the Atmel AVR8 architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to endpoints. - * - * @{ - */ - -#ifndef __ENDPOINT_STREAM_AVR8_H__ -#define __ENDPOINT_STREAM_AVR8_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** Reads and discards the given number of bytes from the currently selected endpoint's bank, - * 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of bytes to discard via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending - * full packets to the host as needed. The last packet is not automatically sent once the - * remaining bytes have been written; the user is responsible for manually sending the last - * packet to the host via the \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of zero bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Endpoint_ClearIN() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for EEPROM source/destination data */ - //@{ - - /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_EStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_EStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE(). - * - * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_EStream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE(). - * - * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_EStream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for PROGMEM source/destination data */ - //@{ - - /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_PStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_PStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Endpoint data stream transmission and reception management for the AVR8 microcontrollers. + * \copydetails Group_EndpointStreamRW_AVR8 + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointStreamRW + * \defgroup Group_EndpointStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8) + * \brief Endpoint data stream transmission and reception management for the Atmel AVR8 architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + * + * @{ + */ + +#ifndef __ENDPOINT_STREAM_AVR8_H__ +#define __ENDPOINT_STREAM_AVR8_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** Reads and discards the given number of bytes from the currently selected endpoint's bank, + * 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of bytes to discard via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending + * full packets to the host as needed. The last packet is not automatically sent once the + * remaining bytes have been written; the user is responsible for manually sending the last + * packet to the host via the \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of zero bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Endpoint_ClearIN() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for EEPROM source/destination data */ + //@{ + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE(). + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE(). + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for PROGMEM source/destination data */ + //@{ + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h index 53316f2f9..f69469f28 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h @@ -1,442 +1,442 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Pipe data stream transmission and reception management for the AVR8 microcontrollers - * \copydetails Group_PipeStreamRW_AVR8 - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_PipeStreamRW - * \defgroup Group_PipeStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8) - * \brief Pipe data stream transmission and reception management for the Atmel AVR8 architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to pipes. - * - * @{ - */ - -#ifndef __PIPE_STREAM_AVR8_H__ -#define __PIPE_STREAM_AVR8_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** 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 device via the \ref Pipe_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or - * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer - * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data - * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with - * the total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to - * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed - * value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Length Number of bytes to discard via the currently selected pipe. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be processed at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device - * as needed. The last packet is not automatically sent once the remaining bytes has been written; the - * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or - * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer - * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data - * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be - * updated with the total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to - * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed - * value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Length Number of zero bytes to write via the currently selected pipe. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be processed at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Pipe_ClearOUT() 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. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the pipe bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Pipe_ClearOUT() 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. - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** 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 - * \ref Pipe_ClearIN() 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. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the pipe bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Pipe_ClearIN() 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. - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for EEPROM source/destination data */ - //@{ - - /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_EStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_EStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_EStream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_EStream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for PROGMEM source/destination data */ - //@{ - - /** FLASH buffer source version of \ref Pipe_Write_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_PStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Pipe_Write_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_PStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Pipe data stream transmission and reception management for the AVR8 microcontrollers + * \copydetails Group_PipeStreamRW_AVR8 + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_PipeStreamRW + * \defgroup Group_PipeStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8) + * \brief Pipe data stream transmission and reception management for the Atmel AVR8 architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to pipes. + * + * @{ + */ + +#ifndef __PIPE_STREAM_AVR8_H__ +#define __PIPE_STREAM_AVR8_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** 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 device via the \ref Pipe_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or + * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer + * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data + * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with + * the total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to + * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed + * value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Length Number of bytes to discard via the currently selected pipe. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be processed at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device + * as needed. The last packet is not automatically sent once the remaining bytes has been written; the + * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or + * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer + * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data + * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be + * updated with the total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to + * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed + * value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Length Number of zero bytes to write via the currently selected pipe. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be processed at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Pipe_ClearOUT() 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. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the pipe bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Pipe_ClearOUT() 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. + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** 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 + * \ref Pipe_ClearIN() 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. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the pipe bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Pipe_ClearIN() 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. + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for EEPROM source/destination data */ + //@{ + + /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_EStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_EStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_EStream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_EStream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for PROGMEM source/destination data */ + //@{ + + /** FLASH buffer source version of \ref Pipe_Write_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_PStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Pipe_Write_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_PStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.c b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.c index 322ad58c7..515461065 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.c +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.c @@ -1,235 +1,235 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#include "../../../../Common/Common.h" -#if (ARCH == ARCH_UC3) - -#define __INCLUDE_FROM_USB_DRIVER -#include "../USBMode.h" - -#if defined(USB_CAN_BE_DEVICE) - -#include "EndpointStream_UC3.h" - -#if !defined(CONTROL_ONLY_DEVICE) -uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Discard_8(); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Write_8(0); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, - * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" -#endif - -#endif - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#endif - -#endif +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_UC3) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "EndpointStream_UC3.h" + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Discard_8(); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Write_8(0); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, + * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" +#endif + +#endif + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#endif + +#endif diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.h index 40a54ee17..3eccb7f15 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.h @@ -1,434 +1,434 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Endpoint data stream transmission and reception management for the AVR32 UC3 microcontrollers. - * \copydetails Group_EndpointStreamRW_UC3 - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_EndpointStreamRW - * \defgroup Group_EndpointStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3) - * \brief Endpoint data stream transmission and reception management for the Atmel AVR32 UC3 architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to endpoints. - * - * @{ - */ - -#ifndef __ENDPOINT_STREAM_UC3_H__ -#define __ENDPOINT_STREAM_UC3_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** Reads and discards the given number of bytes from the currently selected endpoint's bank, - * 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of bytes to discard via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending - * full packets to the host as needed. The last packet is not automatically sent once the - * remaining bytes have been written; the user is responsible for manually sending the last - * packet to the host via the \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of zero bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Endpoint_ClearIN() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Endpoint data stream transmission and reception management for the AVR32 UC3 microcontrollers. + * \copydetails Group_EndpointStreamRW_UC3 + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointStreamRW + * \defgroup Group_EndpointStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3) + * \brief Endpoint data stream transmission and reception management for the Atmel AVR32 UC3 architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + * + * @{ + */ + +#ifndef __ENDPOINT_STREAM_UC3_H__ +#define __ENDPOINT_STREAM_UC3_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** Reads and discards the given number of bytes from the currently selected endpoint's bank, + * 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of bytes to discard via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending + * full packets to the host as needed. The last packet is not automatically sent once the + * remaining bytes have been written; the user is responsible for manually sending the last + * packet to the host via the \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of zero bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Endpoint_ClearIN() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.c b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.c index bb4cbc659..76fbfd8f5 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.c +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.c @@ -1,166 +1,166 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#include "../../../../Common/Common.h" -#if (ARCH == ARCH_UC3) - -#define __INCLUDE_FROM_USB_DRIVER -#include "../USBMode.h" - -#if defined(USB_CAN_BE_HOST) - -#include "PipeStream_UC3.h" - -uint8_t Pipe_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - Pipe_SetPipeToken(PIPE_TOKEN_IN); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearIN(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return PIPE_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - else - { - Pipe_Discard_8(); - - Length--; - BytesInTransfer++; - } - } - - return PIPE_RWSTREAM_NoError; -} - -uint8_t Pipe_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - Pipe_SetPipeToken(PIPE_TOKEN_OUT); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearOUT(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return PIPE_RWSTREAM_IncompleteTransfer; - } - - USB_USBTask(); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - else - { - Pipe_Write_8(0); - - Length--; - BytesInTransfer++; - } - } - - return PIPE_RWSTREAM_NoError; -} - -/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, - * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ - -#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_TOKEN PIPE_TOKEN_OUT -#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr) -#include "Template/Template_Pipe_RW.c" - -#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_TOKEN PIPE_TOKEN_OUT -#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr) -#include "Template/Template_Pipe_RW.c" - -#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_TOKEN PIPE_TOKEN_IN -#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8() -#include "Template/Template_Pipe_RW.c" - -#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_TOKEN PIPE_TOKEN_IN -#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8() -#include "Template/Template_Pipe_RW.c" - -#endif - -#endif +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_UC3) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#include "PipeStream_UC3.h" + +uint8_t Pipe_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + Pipe_SetPipeToken(PIPE_TOKEN_IN); + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return PIPE_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + else + { + Pipe_Discard_8(); + + Length--; + BytesInTransfer++; + } + } + + return PIPE_RWSTREAM_NoError; +} + +uint8_t Pipe_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + Pipe_SetPipeToken(PIPE_TOKEN_OUT); + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return PIPE_RWSTREAM_IncompleteTransfer; + } + + USB_USBTask(); + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + else + { + Pipe_Write_8(0); + + Length--; + BytesInTransfer++; + } + } + + return PIPE_RWSTREAM_NoError; +} + +/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, + * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ + +#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_TOKEN PIPE_TOKEN_OUT +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_TOKEN PIPE_TOKEN_OUT +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_TOKEN PIPE_TOKEN_IN +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8() +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_TOKEN PIPE_TOKEN_IN +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8() +#include "Template/Template_Pipe_RW.c" + +#endif + +#endif diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.h index cb8a28c86..72bf83c6c 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.h @@ -1,352 +1,352 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Pipe data stream transmission and reception management for the AVR32 UC3 microcontrollers. - * \copydetails Group_PipeStreamRW_UC3 - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_PipeStreamRW - * \defgroup Group_PipeStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3) - * \brief Pipe data stream transmission and reception management for the Atmel AVR32 UC3 architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to pipes. - * - * @{ - */ - -#ifndef __PIPE_STREAM_UC3_H__ -#define __PIPE_STREAM_UC3_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** 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 device via the \ref Pipe_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or - * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer - * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data - * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with - * the total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to - * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed - * value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Length Number of bytes to discard via the currently selected pipe. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be processed at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device - * as needed. The last packet is not automatically sent once the remaining bytes has been written; the - * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or - * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer - * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data - * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be - * updated with the total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to - * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed - * value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Length Number of zero bytes to write via the currently selected pipe. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be processed at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Pipe_ClearOUT() 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. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the pipe bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Pipe_ClearOUT() 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. - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** 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 - * \ref Pipe_ClearIN() 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. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the pipe bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Pipe_ClearIN() 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. - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Pipe data stream transmission and reception management for the AVR32 UC3 microcontrollers. + * \copydetails Group_PipeStreamRW_UC3 + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_PipeStreamRW + * \defgroup Group_PipeStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3) + * \brief Pipe data stream transmission and reception management for the Atmel AVR32 UC3 architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to pipes. + * + * @{ + */ + +#ifndef __PIPE_STREAM_UC3_H__ +#define __PIPE_STREAM_UC3_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** 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 device via the \ref Pipe_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or + * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer + * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data + * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with + * the total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to + * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed + * value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Length Number of bytes to discard via the currently selected pipe. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be processed at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device + * as needed. The last packet is not automatically sent once the remaining bytes has been written; the + * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or + * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer + * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data + * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be + * updated with the total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to + * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed + * value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Length Number of zero bytes to write via the currently selected pipe. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be processed at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Pipe_ClearOUT() 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. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the pipe bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Pipe_ClearOUT() 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. + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** 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 + * \ref Pipe_ClearIN() 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. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the pipe bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Pipe_ClearIN() 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. + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c index a2a5c4a96..a4b85e710 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c @@ -52,7 +52,7 @@ void USB_INT_ClearAllInterrupts(void) AVR32_USBB.udintclr = -1; } -ISR(USB_GEN_vect) +ISR(USB_GEN_vect, AVR32_USBB_IRQ_GROUP, 1) { #if defined(USB_CAN_BE_DEVICE) #if !defined(NO_SOF_EVENTS) diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h index 871a0cac2..cfcc5348d 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h @@ -358,7 +358,7 @@ */ void USB_GEN_vect(void); #else - ISR(USB_GEN_vect); + ISR(USB_GEN_vect, AVR32_USBB_IRQ_GROUP, 1); #endif /* Disable C linkage for C++ Compilers: */ diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.c b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.c index 774a574f3..db804506e 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.c +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.c @@ -1,275 +1,275 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) - -#define __INCLUDE_FROM_USB_DRIVER -#include "../USBMode.h" - -#if defined(USB_CAN_BE_DEVICE) - -#include "EndpointStream_XMEGA.h" - -#if !defined(CONTROL_ONLY_DEVICE) -uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Discard_8(); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Write_8(0); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, - * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" -#endif - -#endif - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_Control_R.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_Control_R.c" -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_XMEGA) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "EndpointStream_XMEGA.h" + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Discard_8(); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Write_8(0); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, + * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" #endif -#endif +#endif + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_Control_R.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_Control_R.c" +#endif + +#endif + +#endif diff --git a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.h b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.h index 3269d2b1d..436752880 100644 --- a/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.h +++ b/branches/LUFA-IAR-Port/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.h @@ -1,648 +1,648 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Endpoint data stream transmission and reception management for the AVR XMEGA microcontrollers. - * \copydetails Group_EndpointStreamRW_XMEGA - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_EndpointStreamRW - * \defgroup Group_EndpointStreamRW_XMEGA Read/Write of Multi-Byte Streams (XMEGA) - * \brief Endpoint data stream transmission and reception management for the Atmel AVR XMEGA architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to endpoints. - * - * @{ - */ - -#ifndef __ENDPOINT_STREAM_XMEGA_H__ -#define __ENDPOINT_STREAM_XMEGA_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** Reads and discards the given number of bytes from the currently selected endpoint's bank, - * 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of bytes to discard via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending - * full packets to the host as needed. The last packet is not automatically sent once the - * remaining bytes have been written; the user is responsible for manually sending the last - * packet to the host via the \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of zero bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Endpoint_ClearIN() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for EEPROM source/destination data */ - //@{ - - /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_EStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_EStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE(). - * - * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_EStream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE(). - * - * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_EStream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for PROGMEM source/destination data */ - //@{ - - /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_PStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_PStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Endpoint data stream transmission and reception management for the AVR XMEGA microcontrollers. + * \copydetails Group_EndpointStreamRW_XMEGA + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointStreamRW + * \defgroup Group_EndpointStreamRW_XMEGA Read/Write of Multi-Byte Streams (XMEGA) + * \brief Endpoint data stream transmission and reception management for the Atmel AVR XMEGA architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + * + * @{ + */ + +#ifndef __ENDPOINT_STREAM_XMEGA_H__ +#define __ENDPOINT_STREAM_XMEGA_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** Reads and discards the given number of bytes from the currently selected endpoint's bank, + * 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of bytes to discard via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending + * full packets to the host as needed. The last packet is not automatically sent once the + * remaining bytes have been written; the user is responsible for manually sending the last + * packet to the host via the \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of zero bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Endpoint_ClearIN() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for EEPROM source/destination data */ + //@{ + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE(). + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE(). + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for PROGMEM source/destination data */ + //@{ + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/branches/LUFA-IAR-Port/LUFA/Platform/UC3/ClockManagement.h b/branches/LUFA-IAR-Port/LUFA/Platform/UC3/ClockManagement.h index 51cb0ff6d..ac2431476 100644 --- a/branches/LUFA-IAR-Port/LUFA/Platform/UC3/ClockManagement.h +++ b/branches/LUFA-IAR-Port/LUFA/Platform/UC3/ClockManagement.h @@ -231,6 +231,12 @@ const uint32_t SourceFreq, const uint32_t Frequency) { + if (Channel >= AVR32_PM_GCLK_NUM) + return false; + + if (SourceFreq < Frequency) + return false; + switch (Source) { case CLOCK_SRC_OSC0: @@ -253,9 +259,6 @@ return false; } - if (SourceFreq < Frequency) - return false; - AVR32_PM.GCCTRL[Channel].diven = (SourceFreq > Frequency) ? true : false; AVR32_PM.GCCTRL[Channel].div = (((SourceFreq / Frequency) - 1) / 2); AVR32_PM.GCCTRL[Channel].cen = true; @@ -266,11 +269,18 @@ /** Stops the given generic clock of the UC3 microcontroller. * * \param[in] Channel Index of the generic clock to stop. + * + * \return Boolean \c true if the generic clock was sucessfully stopped, \c false if invalid parameters specified. */ - static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE; - static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) + static inline bool AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE; + static inline bool AVR32CLK_StopGenericClock(const uint8_t Channel) { + if (Channel >= AVR32_PM_GCLK_NUM) + return false; + AVR32_PM.GCCTRL[Channel].cen = false; + + return true; } /** Sets the clock source for the main microcontroller core. The given clock source should be configured @@ -288,8 +298,11 @@ static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source, const uint32_t SourceFreq) { - AVR32_FLASHC.FCR.fws = (SourceFreq > 30000000) ? true : false; + if (SourceFreq > AVR32_PM_CPU_MAX_FREQ) + return false; + AVR32_FLASHC.FCR.fws = (SourceFreq > AVR32_FLASHC_FWS_0_MAX_FREQ) ? true : false; + switch (Source) { #if defined(AVR32_PM_MCCTRL_MCSEL_SLOW) diff --git a/branches/LUFA-IAR-Port/LUFA/Platform/UC3/Exception.S b/branches/LUFA-IAR-Port/LUFA/Platform/UC3/Exception.S index 3162b6960..50f52bddd 100644 --- a/branches/LUFA-IAR-Port/LUFA/Platform/UC3/Exception.S +++ b/branches/LUFA-IAR-Port/LUFA/Platform/UC3/Exception.S @@ -28,106 +28,101 @@ this software. */ -#if defined(__GNUC__) +#if defined(__AVR32__) +#include - #include +.section .exception_handlers, "ax", @progbits - .section .exception_handlers, "ax", @progbits +// ================= EXCEPTION TABLE ================ +.balign 0x200 +.global EVBA_Table +EVBA_Table: - // ================= EXCEPTION TABLE ================ - .balign 0x200 - .global EVBA_Table - EVBA_Table: +.org 0x000 +Exception_Unrecoverable_Exception: + rjmp $ +.org 0x004 +Exception_TLB_Multiple_Hit: + rjmp $ +.org 0x008 +Exception_Bus_Error_Data_Fetch: + rjmp $ +.org 0x00C +Exception_Bus_Error_Instruction_Fetch: + rjmp $ +.org 0x010 +Exception_NMI: + rjmp $ +.org 0x014 +Exception_Instruction_Address: + rjmp $ +.org 0x018 +Exception_ITLB_Protection: + rjmp $ +.org 0x01C +Exception_OCD_Breakpoint: + rjmp $ +.org 0x020 +Exception_Illegal_Opcode: + rjmp $ +.org 0x024 +Exception_Unimplemented_Instruction: + rjmp $ +.org 0x028 +Exception_Privilege_Violation: + rjmp $ +.org 0x02C +Exception_Floating_Point: + rjmp $ +.org 0x030 +Exception_Coprocessor_Absent: + rjmp $ +.org 0x034 +Exception_Data_Address_Read: + rjmp $ +.org 0x038 +Exception_Data_Address_Write: + rjmp $ +.org 0x03C +Exception_DTLB_Protection_Read: + rjmp $ +.org 0x040 +Exception_DTLB_Protection_Write: + rjmp $ +.org 0x044 +Exception_DTLB_Modified: + rjmp $ +.org 0x050 +Exception_ITLB_Miss: + rjmp $ +.org 0x060 +Exception_DTLB_Miss_Read: + rjmp $ +.org 0x070 +Exception_DTLB_Miss_Write: + rjmp $ +.org 0x100 +Exception_Supervisor_Call: + rjmp $ +// ============== END OF EXCEPTION TABLE ============= - .org 0x000 - Exception_Unrecoverable_Exception: - rjmp $ - .org 0x004 - Exception_TLB_Multiple_Hit: - rjmp $ - .org 0x008 - Exception_Bus_Error_Data_Fetch: - rjmp $ - .org 0x00C - Exception_Bus_Error_Instruction_Fetch: - rjmp $ - .org 0x010 - Exception_NMI: - rjmp $ - .org 0x014 - Exception_Instruction_Address: - rjmp $ - .org 0x018 - Exception_ITLB_Protection: - rjmp $ - .org 0x01C - Exception_OCD_Breakpoint: - rjmp $ - .org 0x020 - Exception_Illegal_Opcode: - rjmp $ - .org 0x024 - Exception_Unimplemented_Instruction: - rjmp $ - .org 0x028 - Exception_Privilege_Violation: - rjmp $ - .org 0x02C - Exception_Floating_Point: - rjmp $ - .org 0x030 - Exception_Coprocessor_Absent: - rjmp $ - .org 0x034 - Exception_Data_Address_Read: - rjmp $ - .org 0x038 - Exception_Data_Address_Write: - rjmp $ - .org 0x03C - Exception_DTLB_Protection_Read: - rjmp $ - .org 0x040 - Exception_DTLB_Protection_Write: - rjmp $ - .org 0x044 - Exception_DTLB_Modified: - rjmp $ - .org 0x050 - Exception_ITLB_Miss: - rjmp $ - .org 0x060 - Exception_DTLB_Miss_Read: - rjmp $ - .org 0x070 - Exception_DTLB_Miss_Write: - rjmp $ - .org 0x100 - Exception_Supervisor_Call: - rjmp $ - // ============== END OF EXCEPTION TABLE ============= +// ============= GENERAL INTERRUPT HANDLER =========== +.balign 4 +.irp Level, 0, 1, 2, 3 +Exception_INT\Level: + mov r12, \Level + call INTC_GetInterruptHandler + mov pc, r12 +.endr +// ========= END OF GENERAL INTERRUPT HANDLER ======== - // ============= GENERAL INTERRUPT HANDLER =========== - .balign 4 - .irp Level, 0, 1, 2, 3 - Exception_INT\Level: - mov r12, \Level - call INTC_GetInterruptHandler - mov pc, r12 - .endr - // ========= END OF GENERAL INTERRUPT HANDLER ======== - - // ====== GENERAL INTERRUPT HANDLER OFFSET TABLE ====== - .balign 4 - .global Autovector_Table - Autovector_Table: - .irp Level, 0, 1, 2, 3 - .word ((AVR32_INTC_INT0 + \Level) << AVR32_INTC_IPR_INTLEVEL_OFFSET) | (Exception_INT\Level - EVBA_Table) - .endr - // === END OF GENERAL INTERRUPT HANDLER OFFSET TABLE === - -#elif defined(__AAVR32__) - - END +// ====== GENERAL INTERRUPT HANDLER OFFSET TABLE ====== +.balign 4 +.global Autovector_Table +Autovector_Table: +.irp Level, 0, 1, 2, 3 + .word ((AVR32_INTC_INT0 + \Level) << AVR32_INTC_IPR_INTLEVEL_OFFSET) | (Exception_INT\Level - EVBA_Table) +.endr +// === END OF GENERAL INTERRUPT HANDLER OFFSET TABLE === #endif diff --git a/branches/LUFA-IAR-Port/LUFA/Platform/UC3/InterruptManagement.c b/branches/LUFA-IAR-Port/LUFA/Platform/UC3/InterruptManagement.c index 7602cd485..7ae38d31c 100644 --- a/branches/LUFA-IAR-Port/LUFA/Platform/UC3/InterruptManagement.c +++ b/branches/LUFA-IAR-Port/LUFA/Platform/UC3/InterruptManagement.c @@ -34,18 +34,12 @@ #define __INCLUDE_FROM_INTMANAGEMENT_C #include "InterruptManagement.h" -#if defined(__GNUC__) +#if defined(__GNUC__) || defined(__DOXYGEN__) extern const void EVBA_Table; /** Interrupt vector table, containing the ISR to call for each interrupt group */ InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS]; -/** ISR for unhandled interrupt groups */ -ISR(Unhandled_Interrupt) -{ - for (;;); -} - /** Retrieves the associated interrupt handler for the interrupt group currently being fired. This * is called directly from the exception handler routine before dispatching to the ISR. */ @@ -55,6 +49,16 @@ InterruptHandlerPtr_t INTC_GetInterruptHandler(const uint_reg_t InterruptLevel) } #endif +/** ISR for unhandled interrupt groups */ +#if defined(__GNUC__) || defined(__DOXYGEN__) +ISR(__unhandled_interrupt) +#elif defined(__ICCAVR32__) +__interrupt void __unhandled_interrupt(void) +#endif +{ + for (;;); +} + /** Initializes the interrupt controller ready to handle interrupts. This must be called at the * start of the user program before any interrupts are registered or enabled. */ @@ -63,7 +67,7 @@ void INTC_Init(void) #if defined(__GNUC__) for (uint8_t InterruptGroup = 0; InterruptGroup < AVR32_INTC_NUM_INT_GRPS; InterruptGroup++) { - InterruptHandlers[InterruptGroup] = Unhandled_Interrupt; + InterruptHandlers[InterruptGroup] = __unhandled_interrupt; AVR32_INTC.ipr[InterruptGroup] = Autovector_Table[AVR32_INTC_INT0]; } diff --git a/branches/LUFA-IAR-Port/LUFA/makefile b/branches/LUFA-IAR-Port/LUFA/makefile index ebe2b19be..21f0f578a 100644 --- a/branches/LUFA-IAR-Port/LUFA/makefile +++ b/branches/LUFA-IAR-Port/LUFA/makefile @@ -45,3 +45,6 @@ else include Build/lufa.sources.in include Build/lufa.doxygen.in endif + + +.PHONY: all export_tar version clean \ No newline at end of file diff --git a/branches/LUFA-IAR-Port/Maintenance/makefile b/branches/LUFA-IAR-Port/Maintenance/makefile index 3f542721a..f15838178 100644 --- a/branches/LUFA-IAR-Port/Maintenance/makefile +++ b/branches/LUFA-IAR-Port/Maintenance/makefile @@ -89,3 +89,6 @@ validate-branch: # Validate the working branch for general release, check for placeholder documentation then build and test everything validate-release: check-documentation-placeholders validate-branch + + +.PHONY: all upgrade-doxygen make-as4-projects check-documentation-placeholders validate-branch \ No newline at end of file diff --git a/branches/LUFA-IAR-Port/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c b/branches/LUFA-IAR-Port/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c index b77c18058..6bf74c872 100644 --- a/branches/LUFA-IAR-Port/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c +++ b/branches/LUFA-IAR-Port/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c @@ -361,7 +361,7 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, } /* Program complete - reset timeout */ - wdt_reset(); + TimeoutTicksRemaining = COMMAND_TIMEOUT_TICKS; return ProgrammingStatus; } diff --git a/branches/LUFA-IAR-Port/Projects/AVRISP-MKII/makefile b/branches/LUFA-IAR-Port/Projects/AVRISP-MKII/makefile index 25cd17952..a24ced974 100644 --- a/branches/LUFA-IAR-Port/Projects/AVRISP-MKII/makefile +++ b/branches/LUFA-IAR-Port/Projects/AVRISP-MKII/makefile @@ -32,5 +32,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/Benito/makefile b/branches/LUFA-IAR-Port/Projects/Benito/makefile index b7ec8a9ca..333f2f6a5 100644 --- a/branches/LUFA-IAR-Port/Projects/Benito/makefile +++ b/branches/LUFA-IAR-Port/Projects/Benito/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/HIDReportViewer/makefile b/branches/LUFA-IAR-Port/Projects/HIDReportViewer/makefile index b56e72f6c..ecb4989c1 100644 --- a/branches/LUFA-IAR-Port/Projects/HIDReportViewer/makefile +++ b/branches/LUFA-IAR-Port/Projects/HIDReportViewer/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/LEDNotifier/makefile b/branches/LUFA-IAR-Port/Projects/LEDNotifier/makefile index 1c8e0a744..fa5f9ff46 100644 --- a/branches/LUFA-IAR-Port/Projects/LEDNotifier/makefile +++ b/branches/LUFA-IAR-Port/Projects/LEDNotifier/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/MIDIToneGenerator/makefile b/branches/LUFA-IAR-Port/Projects/MIDIToneGenerator/makefile index 157a651be..0166c62e0 100644 --- a/branches/LUFA-IAR-Port/Projects/MIDIToneGenerator/makefile +++ b/branches/LUFA-IAR-Port/Projects/MIDIToneGenerator/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/Magstripe/makefile b/branches/LUFA-IAR-Port/Projects/Magstripe/makefile index 7e92c1596..94504a0fe 100644 --- a/branches/LUFA-IAR-Port/Projects/Magstripe/makefile +++ b/branches/LUFA-IAR-Port/Projects/Magstripe/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/MediaController/makefile b/branches/LUFA-IAR-Port/Projects/MediaController/makefile index 774e47f26..a87c5574c 100644 --- a/branches/LUFA-IAR-Port/Projects/MediaController/makefile +++ b/branches/LUFA-IAR-Port/Projects/MediaController/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/MissileLauncher/makefile b/branches/LUFA-IAR-Port/Projects/MissileLauncher/makefile index 7e9433c48..de4ec444b 100644 --- a/branches/LUFA-IAR-Port/Projects/MissileLauncher/makefile +++ b/branches/LUFA-IAR-Port/Projects/MissileLauncher/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/RelayBoard/makefile b/branches/LUFA-IAR-Port/Projects/RelayBoard/makefile index 6e680a3dd..553810500 100644 --- a/branches/LUFA-IAR-Port/Projects/RelayBoard/makefile +++ b/branches/LUFA-IAR-Port/Projects/RelayBoard/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/SerialToLCD/makefile b/branches/LUFA-IAR-Port/Projects/SerialToLCD/makefile index 2c74f5fbc..3b4d5aefe 100644 --- a/branches/LUFA-IAR-Port/Projects/SerialToLCD/makefile +++ b/branches/LUFA-IAR-Port/Projects/SerialToLCD/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/TempDataLogger/makefile b/branches/LUFA-IAR-Port/Projects/TempDataLogger/makefile index f5d5bf19b..d851cee5b 100644 --- a/branches/LUFA-IAR-Port/Projects/TempDataLogger/makefile +++ b/branches/LUFA-IAR-Port/Projects/TempDataLogger/makefile @@ -32,5 +32,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/USBtoSerial/makefile b/branches/LUFA-IAR-Port/Projects/USBtoSerial/makefile index 270e9b663..0c837d08b 100644 --- a/branches/LUFA-IAR-Port/Projects/USBtoSerial/makefile +++ b/branches/LUFA-IAR-Port/Projects/USBtoSerial/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/Webserver/makefile b/branches/LUFA-IAR-Port/Projects/Webserver/makefile index d3765ce70..0ef40a526 100644 --- a/branches/LUFA-IAR-Port/Projects/Webserver/makefile +++ b/branches/LUFA-IAR-Port/Projects/Webserver/makefile @@ -34,5 +34,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/Projects/XPLAINBridge/makefile b/branches/LUFA-IAR-Port/Projects/XPLAINBridge/makefile index 6d6c289c5..304649849 100644 --- a/branches/LUFA-IAR-Port/Projects/XPLAINBridge/makefile +++ b/branches/LUFA-IAR-Port/Projects/XPLAINBridge/makefile @@ -37,5 +37,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/branches/LUFA-IAR-Port/makefile b/branches/LUFA-IAR-Port/makefile index d533f25ac..898353c0d 100644 --- a/branches/LUFA-IAR-Port/makefile +++ b/branches/LUFA-IAR-Port/makefile @@ -17,9 +17,9 @@ all: %: @echo Executing \"make $@\" on all LUFA library elements. @echo - $(MAKE) -C LUFA $@ -s - $(MAKE) -C Demos $@ -s - $(MAKE) -C Projects $@ -s - $(MAKE) -C Bootloaders $@ -s + $(MAKE) -C LUFA $@ + $(MAKE) -C Demos $@ + $(MAKE) -C Projects $@ + $(MAKE) -C Bootloaders $@ @echo @echo LUFA \"make $@\" operation complete. diff --git a/trunk/Bootloaders/CDC/BootloaderAPITable.S b/trunk/Bootloaders/CDC/BootloaderAPITable.S index a8e38861d..060a7abea 100644 --- a/trunk/Bootloaders/CDC/BootloaderAPITable.S +++ b/trunk/Bootloaders/CDC/BootloaderAPITable.S @@ -1,6 +1,6 @@ /* LUFA Library - Copyright (C) Dean Camera, 2011. + Copyright (C) Dean Camera, 2012. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org @@ -28,41 +28,44 @@ this software. */ -; Bootloader API Jump Table -.section .apitable, "ax" - ; Trampolines to actual API implementations if the target address is outside the ; range of a rjmp instruction (can happen with large bootloader sections) -.org 0 -BootloaderAPI_ErasePage_Trampoline: - jmp BootloaderAPI_ErasePage -BootloaderAPI_WritePage_Trampoline: - jmp BootloaderAPI_WritePage -BootloaderAPI_FillWord_Trampoline: - jmp BootloaderAPI_FillWord -BootloaderAPI_ReadSignature_Trampoline: - jmp BootloaderAPI_ReadSignature -BootloaderAPI_ReadFuse_Trampoline: - jmp BootloaderAPI_ReadFuse -BootloaderAPI_ReadLock_Trampoline: - jmp BootloaderAPI_ReadLock -BootloaderAPI_WriteLock_Trampoline: - jmp BootloaderAPI_WriteLock -BootloaderAPU_UNUSED1: - ret -BootloaderAPU_UNUSED2: - ret -BootloaderAPU_UNUSED3: - ret -BootloaderAPU_UNUSED4: - ret -BootloaderAPU_UNUSED5: - ret +.section .apitable_trampolines, "ax" +.global BootloaderAPI_Trampolines +BootloaderAPI_Trampolines: + + BootloaderAPI_ErasePage_Trampoline: + jmp BootloaderAPI_ErasePage + BootloaderAPI_WritePage_Trampoline: + jmp BootloaderAPI_WritePage + BootloaderAPI_FillWord_Trampoline: + jmp BootloaderAPI_FillWord + BootloaderAPI_ReadSignature_Trampoline: + jmp BootloaderAPI_ReadSignature + BootloaderAPI_ReadFuse_Trampoline: + jmp BootloaderAPI_ReadFuse + BootloaderAPI_ReadLock_Trampoline: + jmp BootloaderAPI_ReadLock + BootloaderAPI_WriteLock_Trampoline: + jmp BootloaderAPI_WriteLock + BootloaderAPU_UNUSED1: + ret + BootloaderAPU_UNUSED2: + ret + BootloaderAPU_UNUSED3: + ret + BootloaderAPU_UNUSED4: + ret + BootloaderAPU_UNUSED5: + ret + + ; API function jump table -.org (96 - 32) +.section .apitable_jumptable, "ax" .global BootloaderAPI_JumpTable BootloaderAPI_JumpTable: + rjmp BootloaderAPI_ErasePage_Trampoline rjmp BootloaderAPI_WritePage_Trampoline rjmp BootloaderAPI_FillWord_Trampoline @@ -76,10 +79,13 @@ BootloaderAPI_JumpTable: rjmp BootloaderAPU_UNUSED4 ; UNUSED ENTRY 4 rjmp BootloaderAPU_UNUSED5 ; UNUSED ENTRY 5 + + ; Bootloader table signatures and information -.org (96 - 8) -BootloaderAPI_Signatures: +.section .apitable_signatures, "ax" .global BootloaderAPI_Signatures +BootloaderAPI_Signatures: + .long BOOT_START_ADDR ; Start address of the bootloader - .word 0xCDC1 ; Signature for the CDC class bootloader, V1 + .word 0xDFB1 ; Signature for the DFU class bootloader, V1 .word 0xDCFB ; Signature for a LUFA class bootloader diff --git a/trunk/Bootloaders/CDC/makefile b/trunk/Bootloaders/CDC/makefile index 68bf4c63f..2c21fb69f 100644 --- a/trunk/Bootloaders/CDC/makefile +++ b/trunk/Bootloaders/CDC/makefile @@ -15,10 +15,15 @@ FLASH_SIZE_KB := 128 BOOT_SECTION_SIZE_KB := 8 -# Bootloader address calculations (requires the "bc" unix utility) - do -# not modify these calculations, but rather modify the depedant values above. +# Bootloader address calculations (requires the "bc" unix utility) and +# API section start directives - do not modify these macros, but rather +# modify the depedant values above. BOOT_START := 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc) -BOOT_API_TABLESTART := 0x$(shell echo "obase=16; (($(FLASH_SIZE_KB) * 1024) - 96)" | bc) +BOOT_SEC_OFFSET = 0x$(shell echo "obase=16; (($(FLASH_SIZE_KB) * 1024) - $(strip $(1)))" | bc) +BOOT_SECTION_LD_FLAG = -Wl,--section-start=.apitable_$(strip $(1))=$(call BOOT_SEC_OFFSET, $(3)) -Wl,--undefined=BootloaderAPI_$(strip $(2)) +BOOT_API_LD_FLAGS := $(call BOOT_SECTION_LD_FLAG, trampolines, Trampolines, (48 + 32 + 8)) +BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, jumptable, JumpTable, (32 + 8)) +BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, signatures, Signatures, 8) MCU = at90usb1287 ARCH = AVR8 @@ -30,7 +35,7 @@ TARGET = BootloaderCDC SRC = $(TARGET).c Descriptors.c BootloaderAPI.c BootloaderAPITable.S $(LUFA_SRC_USB) LUFA_PATH = ../../LUFA/ CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ -DBOOT_START_ADDR=$(BOOT_START) -LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START) -Wl,--section-start=.apitable=$(BOOT_API_TABLESTART) -Wl,--undefined=BootloaderAPI_JumpTable +LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START) $(BOOT_API_LD_FLAGS) # Default target all: diff --git a/trunk/Bootloaders/DFU/BootloaderAPITable.S b/trunk/Bootloaders/DFU/BootloaderAPITable.S index 18ae390fc..9d1e2fc0e 100644 --- a/trunk/Bootloaders/DFU/BootloaderAPITable.S +++ b/trunk/Bootloaders/DFU/BootloaderAPITable.S @@ -7,7 +7,7 @@ */ /* - Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -28,41 +28,44 @@ this software. */ -; Bootloader API Jump Table -.section .apitable, "ax" - ; Trampolines to actual API implementations if the target address is outside the ; range of a rjmp instruction (can happen with large bootloader sections) -.org 0 -BootloaderAPI_ErasePage_Trampoline: - jmp BootloaderAPI_ErasePage -BootloaderAPI_WritePage_Trampoline: - jmp BootloaderAPI_WritePage -BootloaderAPI_FillWord_Trampoline: - jmp BootloaderAPI_FillWord -BootloaderAPI_ReadSignature_Trampoline: - jmp BootloaderAPI_ReadSignature -BootloaderAPI_ReadFuse_Trampoline: - jmp BootloaderAPI_ReadFuse -BootloaderAPI_ReadLock_Trampoline: - jmp BootloaderAPI_ReadLock -BootloaderAPI_WriteLock_Trampoline: - jmp BootloaderAPI_WriteLock -BootloaderAPU_UNUSED1: - ret -BootloaderAPU_UNUSED2: - ret -BootloaderAPU_UNUSED3: - ret -BootloaderAPU_UNUSED4: - ret -BootloaderAPU_UNUSED5: - ret +.section .apitable_trampolines, "ax" +.global BootloaderAPI_Trampolines +BootloaderAPI_Trampolines: + + BootloaderAPI_ErasePage_Trampoline: + jmp BootloaderAPI_ErasePage + BootloaderAPI_WritePage_Trampoline: + jmp BootloaderAPI_WritePage + BootloaderAPI_FillWord_Trampoline: + jmp BootloaderAPI_FillWord + BootloaderAPI_ReadSignature_Trampoline: + jmp BootloaderAPI_ReadSignature + BootloaderAPI_ReadFuse_Trampoline: + jmp BootloaderAPI_ReadFuse + BootloaderAPI_ReadLock_Trampoline: + jmp BootloaderAPI_ReadLock + BootloaderAPI_WriteLock_Trampoline: + jmp BootloaderAPI_WriteLock + BootloaderAPU_UNUSED1: + ret + BootloaderAPU_UNUSED2: + ret + BootloaderAPU_UNUSED3: + ret + BootloaderAPU_UNUSED4: + ret + BootloaderAPU_UNUSED5: + ret + + ; API function jump table -.org (96 - 32) +.section .apitable_jumptable, "ax" .global BootloaderAPI_JumpTable BootloaderAPI_JumpTable: + rjmp BootloaderAPI_ErasePage_Trampoline rjmp BootloaderAPI_WritePage_Trampoline rjmp BootloaderAPI_FillWord_Trampoline @@ -76,10 +79,13 @@ BootloaderAPI_JumpTable: rjmp BootloaderAPU_UNUSED4 ; UNUSED ENTRY 4 rjmp BootloaderAPU_UNUSED5 ; UNUSED ENTRY 5 + + ; Bootloader table signatures and information -.org (96 - 8) -BootloaderAPI_Signatures: +.section .apitable_signatures, "ax" .global BootloaderAPI_Signatures +BootloaderAPI_Signatures: + .long BOOT_START_ADDR ; Start address of the bootloader .word 0xDFB1 ; Signature for the DFU class bootloader, V1 .word 0xDCFB ; Signature for a LUFA class bootloader diff --git a/trunk/Bootloaders/DFU/Descriptors.c b/trunk/Bootloaders/DFU/Descriptors.c index ff33b6b64..3a1a2e2b3 100644 --- a/trunk/Bootloaders/DFU/Descriptors.c +++ b/trunk/Bootloaders/DFU/Descriptors.c @@ -57,8 +57,8 @@ const USB_Descriptor_Device_t DeviceDescriptor = .ProductID = PRODUCT_ID_CODE, .ReleaseNumber = VERSION_BCD(00.00), - .ManufacturerStrIndex = NO_DESCRIPTOR, - .ProductStrIndex = 0x01, + .ManufacturerStrIndex = 0x01, + .ProductStrIndex = 0x02, .SerialNumStrIndex = NO_DESCRIPTOR, .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS @@ -126,6 +126,17 @@ const USB_Descriptor_String_t LanguageString = .UnicodeString = {LANGUAGE_ID_ENG} }; +/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable + * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device + * Descriptor. + */ +const USB_Descriptor_String_t PROGMEM ManufacturerString = +{ + .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, + + .UnicodeString = L"Dean Camera" +}; + /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * Descriptor. @@ -169,7 +180,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Address = &LanguageString; Size = LanguageString.Header.Size; } - else + else if (DescriptorNumber == 0x01) + { + Address = &ManufacturerString; + Size = ManufacturerString.Header.Size; + } + else if (DescriptorNumber == 0x02) { Address = &ProductString; Size = ProductString.Header.Size; diff --git a/trunk/Bootloaders/DFU/makefile b/trunk/Bootloaders/DFU/makefile index 75b36ec63..3ee61fc8d 100644 --- a/trunk/Bootloaders/DFU/makefile +++ b/trunk/Bootloaders/DFU/makefile @@ -15,10 +15,15 @@ FLASH_SIZE_KB := 128 BOOT_SECTION_SIZE_KB := 8 -# Bootloader address calculations (requires the "bc" unix utility) - do -# not modify these calculations, but rather modify the depedant values above. +# Bootloader address calculations (requires the "bc" unix utility) and +# API section start directives - do not modify these macros, but rather +# modify the depedant values above. BOOT_START := 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc) -BOOT_API_TABLESTART := 0x$(shell echo "obase=16; (($(FLASH_SIZE_KB) * 1024) - 96)" | bc) +BOOT_SEC_OFFSET = 0x$(shell echo "obase=16; (($(FLASH_SIZE_KB) * 1024) - $(strip $(1)))" | bc) +BOOT_SECTION_LD_FLAG = -Wl,--section-start=.apitable_$(strip $(1))=$(call BOOT_SEC_OFFSET, $(3)) -Wl,--undefined=BootloaderAPI_$(strip $(2)) +BOOT_API_LD_FLAGS := $(call BOOT_SECTION_LD_FLAG, trampolines, Trampolines, (48 + 32 + 8)) +BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, jumptable, JumpTable, (32 + 8)) +BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, signatures, Signatures, 8) MCU = at90usb1287 ARCH = AVR8 @@ -30,7 +35,7 @@ TARGET = BootloaderDFU SRC = $(TARGET).c Descriptors.c BootloaderAPI.c BootloaderAPITable.S $(LUFA_SRC_USB) LUFA_PATH = ../../LUFA/ CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ -DBOOT_START_ADDR=$(BOOT_START) -LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START) -Wl,--section-start=.apitable=$(BOOT_API_TABLESTART) -Wl,--undefined=BootloaderAPI_JumpTable +LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START) $(BOOT_API_LD_FLAGS) # Default target all: diff --git a/trunk/BuildTests/BootloaderTest/makefile b/trunk/BuildTests/BootloaderTest/makefile index baee18e86..1294ba084 100644 --- a/trunk/BuildTests/BootloaderTest/makefile +++ b/trunk/BuildTests/BootloaderTest/makefile @@ -41,7 +41,7 @@ testbootloaders: build_flashsize=`echo $$build_cfg | cut -d':' -f4`; \ build_bootsize=`echo $$build_cfg | cut -d':' -f5`; \ \ - printf "Found bootloader configuration for bootloader '%s' (FLASH: %3s KB | BOOT: %3s KB | MCU: %12s / %4s)\n" $$build_bootloader $$build_flashsize $$build_bootsize $$build_mcu $$build_arch; \ + printf "Found '%s' bootloader configuration (FLASH: %3s KB | BOOT: %3s KB | MCU: %12s / %4s)\n" $$build_bootloader $$build_flashsize $$build_bootsize $$build_mcu $$build_arch; \ \ printf "\t@echo Building bootloader %s - %s - FLASH: %s KB, BOOT: %s KB\n" $$build_bootloader $$build_mcu $$build_flashsize $$build_bootsize >> BuildMakefile; \ printf "\t$(MAKE) -s -C $(patsubst %/,%,$(LUFA_PATH))/../Bootloaders/%s/ clean elf ARCH=%s MCU=%s BOARD=%s FLASH_SIZE_KB=%s BOOT_SECTION_SIZE_KB=%s\n\n" $$build_bootloader $$build_arch $$build_mcu $$build_board $$build_flashsize $$build_bootsize >> BuildMakefile; \ diff --git a/trunk/BuildTests/ModuleTest/makefile b/trunk/BuildTests/ModuleTest/makefile index 8a20d0452..b997b3513 100644 --- a/trunk/BuildTests/ModuleTest/makefile +++ b/trunk/BuildTests/ModuleTest/makefile @@ -39,12 +39,15 @@ end: @echo %.avr8: + @echo Building ModuleTest for ARCH=AVR8 MCU=$(@:%.avr8=%)... $(MAKE) -s -f makefile.test clean elf ARCH=AVR8 MCU=$(@:%.avr8=%) %.xmega: + @echo Building ModuleTest for ARCH=XMEGA MCU=$(@:%.xmega=%)... $(MAKE) -s -f makefile.test clean elf ARCH=XMEGA MCU=$(@:%.xmega=%) %.uc3: + @echo Building ModuleTest for ARCH=UC3 MCU=$(@:%.uc3=%)... $(MAKE) -s -f makefile.test clean elf ARCH=UC3 MCU=$(@:%.uc3=%) clean: diff --git a/trunk/BuildTests/SingleUSBModeTest/makefile b/trunk/BuildTests/SingleUSBModeTest/makefile index 6b5af1eb2..d5fd3f06e 100644 --- a/trunk/BuildTests/SingleUSBModeTest/makefile +++ b/trunk/BuildTests/SingleUSBModeTest/makefile @@ -25,12 +25,19 @@ end: @echo compile: + @echo Building SingleUSBModeTest for ARCH=AVR8 in device only mode... $(MAKE) -s -f makefile.test clean elf ARCH=AVR8 MCU=at90usb1287 CC_FLAGS='-D USB_DEVICE_ONLY' + + @echo Building SingleUSBModeTest for ARCH=AVR8 in host only mode... $(MAKE) -s -f makefile.test clean elf ARCH=AVR8 MCU=at90usb1287 CC_FLAGS='-D USB_HOST_ONLY' + @echo Building SingleUSBModeTest for ARCH=XMEGA in device only mode... $(MAKE) -s -f makefile.test clean elf ARCH=XMEGA MCU=atxmega128a1u CC_FLAGS='-D USB_DEVICE_ONLY' + @echo Building SingleUSBModeTest for ARCH=UC3 in device only mode... $(MAKE) -s -f makefile.test clean elf ARCH=UC3 MCU=uc3a0256 CC_FLAGS='-D USB_DEVICE_ONLY' + + @echo Building SingleUSBModeTest for ARCH=UC3 in host only mode... $(MAKE) -s -f makefile.test clean elf ARCH=UC3 MCU=uc3a0256 CC_FLAGS='-D USB_HOST_ONLY' clean: diff --git a/trunk/Demos/Device/ClassDriver/AudioInput/makefile b/trunk/Demos/Device/ClassDriver/AudioInput/makefile index 44f445f3a..1b251cd50 100644 --- a/trunk/Demos/Device/ClassDriver/AudioInput/makefile +++ b/trunk/Demos/Device/ClassDriver/AudioInput/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/AudioOutput/makefile b/trunk/Demos/Device/ClassDriver/AudioOutput/makefile index f6f6da025..904e13684 100644 --- a/trunk/Demos/Device/ClassDriver/AudioOutput/makefile +++ b/trunk/Demos/Device/ClassDriver/AudioOutput/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/DualVirtualSerial/makefile b/trunk/Demos/Device/ClassDriver/DualVirtualSerial/makefile index 606c37747..ce751a865 100644 --- a/trunk/Demos/Device/ClassDriver/DualVirtualSerial/makefile +++ b/trunk/Demos/Device/ClassDriver/DualVirtualSerial/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/GenericHID/makefile b/trunk/Demos/Device/ClassDriver/GenericHID/makefile index 2521616eb..5a4b85bf3 100644 --- a/trunk/Demos/Device/ClassDriver/GenericHID/makefile +++ b/trunk/Demos/Device/ClassDriver/GenericHID/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/Joystick/makefile b/trunk/Demos/Device/ClassDriver/Joystick/makefile index 2525a7de4..926a50d81 100644 --- a/trunk/Demos/Device/ClassDriver/Joystick/makefile +++ b/trunk/Demos/Device/ClassDriver/Joystick/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/Keyboard/makefile b/trunk/Demos/Device/ClassDriver/Keyboard/makefile index d8d7ce0d6..346f428dd 100644 --- a/trunk/Demos/Device/ClassDriver/Keyboard/makefile +++ b/trunk/Demos/Device/ClassDriver/Keyboard/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/KeyboardMouse/makefile b/trunk/Demos/Device/ClassDriver/KeyboardMouse/makefile index 54cc5522f..4727bb1bf 100644 --- a/trunk/Demos/Device/ClassDriver/KeyboardMouse/makefile +++ b/trunk/Demos/Device/ClassDriver/KeyboardMouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/KeyboardMouseMultiReport/makefile b/trunk/Demos/Device/ClassDriver/KeyboardMouseMultiReport/makefile index 874dc732d..e27213bd7 100644 --- a/trunk/Demos/Device/ClassDriver/KeyboardMouseMultiReport/makefile +++ b/trunk/Demos/Device/ClassDriver/KeyboardMouseMultiReport/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/MIDI/makefile b/trunk/Demos/Device/ClassDriver/MIDI/makefile index 94ed2be30..6e5f7d36e 100644 --- a/trunk/Demos/Device/ClassDriver/MIDI/makefile +++ b/trunk/Demos/Device/ClassDriver/MIDI/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/MassStorage/makefile b/trunk/Demos/Device/ClassDriver/MassStorage/makefile index dc13db9ca..4d2d5d03d 100644 --- a/trunk/Demos/Device/ClassDriver/MassStorage/makefile +++ b/trunk/Demos/Device/ClassDriver/MassStorage/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in \ No newline at end of file diff --git a/trunk/Demos/Device/ClassDriver/MassStorageKeyboard/makefile b/trunk/Demos/Device/ClassDriver/MassStorageKeyboard/makefile index 385e5f6ce..2e410c869 100644 --- a/trunk/Demos/Device/ClassDriver/MassStorageKeyboard/makefile +++ b/trunk/Demos/Device/ClassDriver/MassStorageKeyboard/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/Mouse/makefile b/trunk/Demos/Device/ClassDriver/Mouse/makefile index 8b3ec13b4..d4781581c 100644 --- a/trunk/Demos/Device/ClassDriver/Mouse/makefile +++ b/trunk/Demos/Device/ClassDriver/Mouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/RNDISEthernet/makefile b/trunk/Demos/Device/ClassDriver/RNDISEthernet/makefile index 042c4f241..80242eadc 100644 --- a/trunk/Demos/Device/ClassDriver/RNDISEthernet/makefile +++ b/trunk/Demos/Device/ClassDriver/RNDISEthernet/makefile @@ -32,5 +32,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/VirtualSerial/makefile b/trunk/Demos/Device/ClassDriver/VirtualSerial/makefile index 5c1cc1c34..da7c8a38c 100644 --- a/trunk/Demos/Device/ClassDriver/VirtualSerial/makefile +++ b/trunk/Demos/Device/ClassDriver/VirtualSerial/makefile @@ -28,6 +28,9 @@ all: include $(LUFA_PATH)/Build/lufa.core.in include $(LUFA_PATH)/Build/lufa.sources.in include $(LUFA_PATH)/Build/lufa.build.in +include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in +include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/VirtualSerialMassStorage/makefile b/trunk/Demos/Device/ClassDriver/VirtualSerialMassStorage/makefile index 9587672b5..0665a7f25 100644 --- a/trunk/Demos/Device/ClassDriver/VirtualSerialMassStorage/makefile +++ b/trunk/Demos/Device/ClassDriver/VirtualSerialMassStorage/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/ClassDriver/VirtualSerialMouse/makefile b/trunk/Demos/Device/ClassDriver/VirtualSerialMouse/makefile index 386cd6502..67e7e365e 100644 --- a/trunk/Demos/Device/ClassDriver/VirtualSerialMouse/makefile +++ b/trunk/Demos/Device/ClassDriver/VirtualSerialMouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/Incomplete/Sideshow/makefile b/trunk/Demos/Device/Incomplete/Sideshow/makefile index b5a459386..2f032f394 100644 --- a/trunk/Demos/Device/Incomplete/Sideshow/makefile +++ b/trunk/Demos/Device/Incomplete/Sideshow/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h b/trunk/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h index e45654a27..17f68f3a3 100644 --- a/trunk/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h +++ b/trunk/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h @@ -1,84 +1,84 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Copyright 2010 Peter Lawrence (majbthrd [at] gmail [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for Descriptors.c. - */ - -#ifndef _DESCRIPTORS_H_ -#define _DESCRIPTORS_H_ - - /* Includes: */ - #include - - #include - - /* Macros: */ - /** Endpoint address of the TMC notification IN endpoint. */ - #define TMC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2) - - /** Endpoint address of the TMC device-to-host data IN endpoint. */ - #define TMC_IN_EPADDR (ENDPOINT_DIR_IN | 3) - - /** Endpoint address of the TMC host-to-device data OUT endpoint. */ - #define TMC_OUT_EPADDR (ENDPOINT_DIR_OUT | 4) - - /** Size in bytes of the TMC data endpoints. */ - #define TMC_IO_EPSIZE 64 - - /** Size in bytes of the TMC notification endpoint. */ - #define TMC_NOTIFICATION_EPSIZE 8 - - /* Type Defines: */ - /** Type define for the device configuration descriptor structure. This must be defined in the - * application code, as the configuration descriptor contains several sub-descriptors which - * vary between devices, and which describe the device's usage to the host. - */ - typedef struct - { - USB_Descriptor_Configuration_Header_t Config; - - // Test and Measurement Interface - USB_Descriptor_Interface_t TM_Interface; - USB_Descriptor_Endpoint_t TM_DataOutEndpoint; - USB_Descriptor_Endpoint_t TM_DataInEndpoint; - USB_Descriptor_Endpoint_t TM_NotificationEndpoint; - } USB_Descriptor_Configuration_t; - - /* Function Prototypes: */ - uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, - const uint8_t wIndex, - const void** const DescriptorAddress) - ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); - -#endif +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Peter Lawrence (majbthrd [at] gmail [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for Descriptors.c. + */ + +#ifndef _DESCRIPTORS_H_ +#define _DESCRIPTORS_H_ + + /* Includes: */ + #include + + #include + + /* Macros: */ + /** Endpoint address of the TMC notification IN endpoint. */ + #define TMC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2) + + /** Endpoint address of the TMC device-to-host data IN endpoint. */ + #define TMC_IN_EPADDR (ENDPOINT_DIR_IN | 3) + + /** Endpoint address of the TMC host-to-device data OUT endpoint. */ + #define TMC_OUT_EPADDR (ENDPOINT_DIR_OUT | 4) + + /** Size in bytes of the TMC data endpoints. */ + #define TMC_IO_EPSIZE 64 + + /** Size in bytes of the TMC notification endpoint. */ + #define TMC_NOTIFICATION_EPSIZE 8 + + /* Type Defines: */ + /** Type define for the device configuration descriptor structure. This must be defined in the + * application code, as the configuration descriptor contains several sub-descriptors which + * vary between devices, and which describe the device's usage to the host. + */ + typedef struct + { + USB_Descriptor_Configuration_Header_t Config; + + // Test and Measurement Interface + USB_Descriptor_Interface_t TM_Interface; + USB_Descriptor_Endpoint_t TM_DataOutEndpoint; + USB_Descriptor_Endpoint_t TM_DataInEndpoint; + USB_Descriptor_Endpoint_t TM_NotificationEndpoint; + } USB_Descriptor_Configuration_t; + + /* Function Prototypes: */ + uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, + const uint8_t wIndex, + const void** const DescriptorAddress) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); + +#endif diff --git a/trunk/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h b/trunk/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h index bd93154f8..9fa9f23d0 100644 --- a/trunk/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h +++ b/trunk/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h @@ -1,149 +1,149 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#ifndef _TESTANDMEASUREMENT_H_ -#define _TESTANDMEASUREMENT_H_ - - /* Includes: */ - #include - #include - #include - #include - - #include "Descriptors.h" - - #include - #include - - /* Macros: */ - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is busy. */ - #define LEDMASK_USB_BUSY LEDS_LED2 - - #define Req_InitiateAbortBulkOut 0x01 - #define Req_CheckAbortBulkOutStatus 0x02 - #define Req_InitiateAbortBulkIn 0x03 - #define Req_CheckAbortBulkInStatus 0x04 - #define Req_InitiateClear 0x05 - #define Req_CheckClearStatus 0x06 - #define Req_GetCapabilities 0x07 - #define Req_IndicatorPulse 0x40 - - #define TMC_STATUS_SUCCESS 0x01 - #define TMC_STATUS_PENDING 0x02 - #define TMC_STATUS_FAILED 0x80 - #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81 - #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82 - #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83 - - #define TMC_MESSAGEID_DEV_DEP_MSG_OUT 0x01 - #define TMC_MESSAGEID_DEV_DEP_MSG_IN 0x02 - #define TMC_MESSAGEID_DEV_VENDOR_OUT 0x7E - #define TMC_MESSAGEID_DEV_VENDOR_IN 0x7F - - /* Type Defines */ - typedef struct - { - uint8_t Status; - uint8_t Reserved; - - uint16_t TMCVersion; - - struct - { - unsigned ListenOnly : 1; - unsigned TalkOnly : 1; - unsigned PulseIndicateSupported : 1; - unsigned Reserved : 5; - } Interface; - - struct - { - unsigned SupportsAbortINOnMatch : 1; - unsigned Reserved : 7; - } Device; - - uint8_t Reserved2[6]; - uint8_t Reserved3[12]; - } TMC_Capabilities_t; - - typedef struct - { - uint8_t LastMessageTransaction; - uint8_t TermChar; - uint8_t Reserved[2]; - } TMC_DevOUTMessageHeader_t; - - typedef struct - { - uint8_t LastMessageTransaction; - uint8_t Reserved[3]; - } TMC_DevINMessageHeader_t; - - typedef struct - { - uint8_t MessageID; - uint8_t Tag; - uint8_t InverseTag; - uint8_t Reserved; - uint32_t TransferSize; - - union - { - TMC_DevOUTMessageHeader_t DeviceOUT; - TMC_DevINMessageHeader_t DeviceIN; - uint32_t VendorSpecific; - } MessageIDSpecific; - } TMC_MessageHeader_t; - - /* Function Prototypes: */ - void SetupHardware(void); - void TMC_Task(void); - bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader); - bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader); - - void EVENT_USB_Device_Connect(void); - void EVENT_USB_Device_Disconnect(void); - void EVENT_USB_Device_ConfigurationChanged(void); - void EVENT_USB_Device_ControlRequest(void); - -#endif +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#ifndef _TESTANDMEASUREMENT_H_ +#define _TESTANDMEASUREMENT_H_ + + /* Includes: */ + #include + #include + #include + #include + + #include "Descriptors.h" + + #include + #include + + /* Macros: */ + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is busy. */ + #define LEDMASK_USB_BUSY LEDS_LED2 + + #define Req_InitiateAbortBulkOut 0x01 + #define Req_CheckAbortBulkOutStatus 0x02 + #define Req_InitiateAbortBulkIn 0x03 + #define Req_CheckAbortBulkInStatus 0x04 + #define Req_InitiateClear 0x05 + #define Req_CheckClearStatus 0x06 + #define Req_GetCapabilities 0x07 + #define Req_IndicatorPulse 0x40 + + #define TMC_STATUS_SUCCESS 0x01 + #define TMC_STATUS_PENDING 0x02 + #define TMC_STATUS_FAILED 0x80 + #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81 + #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82 + #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83 + + #define TMC_MESSAGEID_DEV_DEP_MSG_OUT 0x01 + #define TMC_MESSAGEID_DEV_DEP_MSG_IN 0x02 + #define TMC_MESSAGEID_DEV_VENDOR_OUT 0x7E + #define TMC_MESSAGEID_DEV_VENDOR_IN 0x7F + + /* Type Defines */ + typedef struct + { + uint8_t Status; + uint8_t Reserved; + + uint16_t TMCVersion; + + struct + { + unsigned ListenOnly : 1; + unsigned TalkOnly : 1; + unsigned PulseIndicateSupported : 1; + unsigned Reserved : 5; + } Interface; + + struct + { + unsigned SupportsAbortINOnMatch : 1; + unsigned Reserved : 7; + } Device; + + uint8_t Reserved2[6]; + uint8_t Reserved3[12]; + } TMC_Capabilities_t; + + typedef struct + { + uint8_t LastMessageTransaction; + uint8_t TermChar; + uint8_t Reserved[2]; + } TMC_DevOUTMessageHeader_t; + + typedef struct + { + uint8_t LastMessageTransaction; + uint8_t Reserved[3]; + } TMC_DevINMessageHeader_t; + + typedef struct + { + uint8_t MessageID; + uint8_t Tag; + uint8_t InverseTag; + uint8_t Reserved; + uint32_t TransferSize; + + union + { + TMC_DevOUTMessageHeader_t DeviceOUT; + TMC_DevINMessageHeader_t DeviceIN; + uint32_t VendorSpecific; + } MessageIDSpecific; + } TMC_MessageHeader_t; + + /* Function Prototypes: */ + void SetupHardware(void); + void TMC_Task(void); + bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader); + bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader); + + void EVENT_USB_Device_Connect(void); + void EVENT_USB_Device_Disconnect(void); + void EVENT_USB_Device_ConfigurationChanged(void); + void EVENT_USB_Device_ControlRequest(void); + +#endif diff --git a/trunk/Demos/Device/Incomplete/TestAndMeasurement/makefile b/trunk/Demos/Device/Incomplete/TestAndMeasurement/makefile index cbd43194e..f59981dc4 100644 --- a/trunk/Demos/Device/Incomplete/TestAndMeasurement/makefile +++ b/trunk/Demos/Device/Incomplete/TestAndMeasurement/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/AudioInput/makefile b/trunk/Demos/Device/LowLevel/AudioInput/makefile index 9748d897c..477221cb4 100644 --- a/trunk/Demos/Device/LowLevel/AudioInput/makefile +++ b/trunk/Demos/Device/LowLevel/AudioInput/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/AudioOutput/makefile b/trunk/Demos/Device/LowLevel/AudioOutput/makefile index 9fa01dd60..38fb012d2 100644 --- a/trunk/Demos/Device/LowLevel/AudioOutput/makefile +++ b/trunk/Demos/Device/LowLevel/AudioOutput/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/DualVirtualSerial/makefile b/trunk/Demos/Device/LowLevel/DualVirtualSerial/makefile index 81add683c..4cb9057d7 100644 --- a/trunk/Demos/Device/LowLevel/DualVirtualSerial/makefile +++ b/trunk/Demos/Device/LowLevel/DualVirtualSerial/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/GenericHID/makefile b/trunk/Demos/Device/LowLevel/GenericHID/makefile index 17f61929f..9a35c6d2e 100644 --- a/trunk/Demos/Device/LowLevel/GenericHID/makefile +++ b/trunk/Demos/Device/LowLevel/GenericHID/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/Joystick/makefile b/trunk/Demos/Device/LowLevel/Joystick/makefile index 162328652..1e2e6ee45 100644 --- a/trunk/Demos/Device/LowLevel/Joystick/makefile +++ b/trunk/Demos/Device/LowLevel/Joystick/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/Keyboard/makefile b/trunk/Demos/Device/LowLevel/Keyboard/makefile index c1fe9720b..af67b625a 100644 --- a/trunk/Demos/Device/LowLevel/Keyboard/makefile +++ b/trunk/Demos/Device/LowLevel/Keyboard/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/KeyboardMouse/makefile b/trunk/Demos/Device/LowLevel/KeyboardMouse/makefile index b89c33d1c..3485e7f83 100644 --- a/trunk/Demos/Device/LowLevel/KeyboardMouse/makefile +++ b/trunk/Demos/Device/LowLevel/KeyboardMouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/MIDI/makefile b/trunk/Demos/Device/LowLevel/MIDI/makefile index f8c258ff6..5290fe665 100644 --- a/trunk/Demos/Device/LowLevel/MIDI/makefile +++ b/trunk/Demos/Device/LowLevel/MIDI/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/MassStorage/makefile b/trunk/Demos/Device/LowLevel/MassStorage/makefile index 22bc7eef4..7ea0abfc5 100644 --- a/trunk/Demos/Device/LowLevel/MassStorage/makefile +++ b/trunk/Demos/Device/LowLevel/MassStorage/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/Mouse/makefile b/trunk/Demos/Device/LowLevel/Mouse/makefile index ace12363f..5552aee5a 100644 --- a/trunk/Demos/Device/LowLevel/Mouse/makefile +++ b/trunk/Demos/Device/LowLevel/Mouse/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/RNDISEthernet/makefile b/trunk/Demos/Device/LowLevel/RNDISEthernet/makefile index fe9256774..c6c867be8 100644 --- a/trunk/Demos/Device/LowLevel/RNDISEthernet/makefile +++ b/trunk/Demos/Device/LowLevel/RNDISEthernet/makefile @@ -32,5 +32,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Device/LowLevel/VirtualSerial/makefile b/trunk/Demos/Device/LowLevel/VirtualSerial/makefile index 930c1d202..8ab7f5278 100644 --- a/trunk/Demos/Device/LowLevel/VirtualSerial/makefile +++ b/trunk/Demos/Device/LowLevel/VirtualSerial/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/DualRole/ClassDriver/MouseHostDevice/makefile b/trunk/Demos/DualRole/ClassDriver/MouseHostDevice/makefile index 3458943d4..c30b35361 100644 --- a/trunk/Demos/DualRole/ClassDriver/MouseHostDevice/makefile +++ b/trunk/Demos/DualRole/ClassDriver/MouseHostDevice/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.c b/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.c index 4c53cc221..b1e988cca 100644 --- a/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.c +++ b/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.c @@ -1,232 +1,232 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Main source file for the AndroidAccessoryHost demo. This file contains the main tasks of - * the demo and is responsible for the initial application hardware configuration. - */ - -#include "AndroidAccessoryHost.h" - -/** LUFA Android Open Accessory Class driver interface configuration and state information. This - * structure is passed to all Android Open Accessory Class driver functions, so that multiple - * instances of the same class within a device can be differentiated from one another. - */ -USB_ClassInfo_AOA_Host_t AndroidDevice_AOA_Interface = - { - .Config = - { - .DataINPipe = - { - .Address = (PIPE_DIR_IN | 1), - .Banks = 1, - }, - .DataOUTPipe = - { - .Address = (PIPE_DIR_OUT | 2), - .Banks = 1, - }, - .PropertyStrings = - { - [AOA_STRING_Manufacturer] = "Dean Camera", - [AOA_STRING_Model] = "LUFA Android Demo", - [AOA_STRING_Description] = "LUFA Android Demo", - [AOA_STRING_Version] = "1.0", - [AOA_STRING_URI] = "http://www.lufa-lib.org", - [AOA_STRING_Serial] = "0000000012345678", - }, - }, - }; - - -/** Main program entry point. This routine configures the hardware required by the application, then - * enters a loop to run the application tasks in sequence. - */ -int main(void) -{ - SetupHardware(); - - puts_P(PSTR(ESC_FG_CYAN "Android Accessory Host Demo running.\r\n" ESC_FG_WHITE)); - - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - sei(); - - for (;;) - { - AOAHost_Task(); - - AOA_Host_USBTask(&AndroidDevice_AOA_Interface); - USB_USBTask(); - } -} - -/** Configures the board hardware and chip peripherals for the demo's functionality. */ -void SetupHardware(void) -{ - /* Disable watchdog if enabled by bootloader/fuses */ - MCUSR &= ~(1 << WDRF); - wdt_disable(); - - /* Disable clock division */ - clock_prescale_set(clock_div_1); - - /* Hardware Initialization */ - Serial_Init(9600, false); - LEDs_Init(); - USB_Init(); - - /* Create a stdio stream for the serial port for stdin and stdout */ - Serial_CreateStream(NULL); -} - -/** Task to manage an enumerated USB Android Accessory device once connected, to print received data - * from the device to the serial port. - */ -void AOAHost_Task(void) -{ - if (USB_HostState != HOST_STATE_Configured) - return; - - if (AOA_Host_BytesReceived(&AndroidDevice_AOA_Interface)) - { - /* Echo received bytes from the attached device through the USART */ - int16_t ReceivedByte = AOA_Host_ReceiveByte(&AndroidDevice_AOA_Interface); - if (!(ReceivedByte < 0)) - putchar(ReceivedByte); - } -} - -/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and - * starts the library USB task to begin the enumeration and USB management process. - */ -void EVENT_USB_Host_DeviceAttached(void) -{ - puts_P(PSTR("Device Attached.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); -} - -/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and - * stops the library USB task management process. - */ -void EVENT_USB_Host_DeviceUnattached(void) -{ - puts_P(PSTR("\r\nDevice Unattached.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); -} - -/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully - * enumerated by the host and is now ready to be used by the application. - */ -void EVENT_USB_Host_DeviceEnumerationComplete(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); - - USB_Descriptor_Device_t DeviceDescriptor; - - if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful) - { - puts_P(PSTR("Error Retrieving Device Descriptor.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - bool NeedModeSwitch; - if (!(AOA_Host_ValidateAccessoryDevice(&AndroidDevice_AOA_Interface, &DeviceDescriptor, &NeedModeSwitch))) - { - puts_P(PSTR("Not an Android device.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - if (NeedModeSwitch) - { - puts_P(PSTR("Not in Accessory mode, switching...\r\n")); - AOA_Host_StartAccessoryMode(&AndroidDevice_AOA_Interface); - return; - } - - uint16_t ConfigDescriptorSize; - uint8_t ConfigDescriptorData[512]; - - if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData, - sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) - { - puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - if (AOA_Host_ConfigurePipes(&AndroidDevice_AOA_Interface, - ConfigDescriptorSize, ConfigDescriptorData) != AOA_ENUMERROR_NoError) - { - puts_P(PSTR("Attached Device Not a Valid Android Accessory Class Device.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful) - { - puts_P(PSTR("Error Setting Device Configuration.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - return; - } - - puts_P(PSTR("Android Device Enumerated.\r\n")); - LEDs_SetAllLEDs(LEDMASK_USB_READY); -} - -/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ -void EVENT_USB_Host_HostError(const uint8_t ErrorCode) -{ - USB_Disable(); - - printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n" - " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); - - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - for(;;); -} - -/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while - * enumerating an attached USB device. - */ -void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, - const uint8_t SubErrorCode) -{ - printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n" - " -- Error Code %d\r\n" - " -- Sub Error Code %d\r\n" - " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState); - - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); -} - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Main source file for the AndroidAccessoryHost demo. This file contains the main tasks of + * the demo and is responsible for the initial application hardware configuration. + */ + +#include "AndroidAccessoryHost.h" + +/** LUFA Android Open Accessory Class driver interface configuration and state information. This + * structure is passed to all Android Open Accessory Class driver functions, so that multiple + * instances of the same class within a device can be differentiated from one another. + */ +USB_ClassInfo_AOA_Host_t AndroidDevice_AOA_Interface = + { + .Config = + { + .DataINPipe = + { + .Address = (PIPE_DIR_IN | 1), + .Banks = 1, + }, + .DataOUTPipe = + { + .Address = (PIPE_DIR_OUT | 2), + .Banks = 1, + }, + .PropertyStrings = + { + [AOA_STRING_Manufacturer] = "Dean Camera", + [AOA_STRING_Model] = "LUFA Android Demo", + [AOA_STRING_Description] = "LUFA Android Demo", + [AOA_STRING_Version] = "1.0", + [AOA_STRING_URI] = "http://www.lufa-lib.org", + [AOA_STRING_Serial] = "0000000012345678", + }, + }, + }; + + +/** Main program entry point. This routine configures the hardware required by the application, then + * enters a loop to run the application tasks in sequence. + */ +int main(void) +{ + SetupHardware(); + + puts_P(PSTR(ESC_FG_CYAN "Android Accessory Host Demo running.\r\n" ESC_FG_WHITE)); + + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); + sei(); + + for (;;) + { + AOAHost_Task(); + + AOA_Host_USBTask(&AndroidDevice_AOA_Interface); + USB_USBTask(); + } +} + +/** Configures the board hardware and chip peripherals for the demo's functionality. */ +void SetupHardware(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + /* Hardware Initialization */ + Serial_Init(9600, false); + LEDs_Init(); + USB_Init(); + + /* Create a stdio stream for the serial port for stdin and stdout */ + Serial_CreateStream(NULL); +} + +/** Task to manage an enumerated USB Android Accessory device once connected, to print received data + * from the device to the serial port. + */ +void AOAHost_Task(void) +{ + if (USB_HostState != HOST_STATE_Configured) + return; + + if (AOA_Host_BytesReceived(&AndroidDevice_AOA_Interface)) + { + /* Echo received bytes from the attached device through the USART */ + int16_t ReceivedByte = AOA_Host_ReceiveByte(&AndroidDevice_AOA_Interface); + if (!(ReceivedByte < 0)) + putchar(ReceivedByte); + } +} + +/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and + * starts the library USB task to begin the enumeration and USB management process. + */ +void EVENT_USB_Host_DeviceAttached(void) +{ + puts_P(PSTR("Device Attached.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); +} + +/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and + * stops the library USB task management process. + */ +void EVENT_USB_Host_DeviceUnattached(void) +{ + puts_P(PSTR("\r\nDevice Unattached.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); +} + +/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully + * enumerated by the host and is now ready to be used by the application. + */ +void EVENT_USB_Host_DeviceEnumerationComplete(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); + + USB_Descriptor_Device_t DeviceDescriptor; + + if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful) + { + puts_P(PSTR("Error Retrieving Device Descriptor.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + bool NeedModeSwitch; + if (!(AOA_Host_ValidateAccessoryDevice(&AndroidDevice_AOA_Interface, &DeviceDescriptor, &NeedModeSwitch))) + { + puts_P(PSTR("Not an Android device.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + if (NeedModeSwitch) + { + puts_P(PSTR("Not in Accessory mode, switching...\r\n")); + AOA_Host_StartAccessoryMode(&AndroidDevice_AOA_Interface); + return; + } + + uint16_t ConfigDescriptorSize; + uint8_t ConfigDescriptorData[512]; + + if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData, + sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) + { + puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + if (AOA_Host_ConfigurePipes(&AndroidDevice_AOA_Interface, + ConfigDescriptorSize, ConfigDescriptorData) != AOA_ENUMERROR_NoError) + { + puts_P(PSTR("Attached Device Not a Valid Android Accessory Class Device.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful) + { + puts_P(PSTR("Error Setting Device Configuration.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + return; + } + + puts_P(PSTR("Android Device Enumerated.\r\n")); + LEDs_SetAllLEDs(LEDMASK_USB_READY); +} + +/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ +void EVENT_USB_Host_HostError(const uint8_t ErrorCode) +{ + USB_Disable(); + + printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n" + " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); + + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + for(;;); +} + +/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while + * enumerating an attached USB device. + */ +void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, + const uint8_t SubErrorCode) +{ + printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n" + " -- Error Code %d\r\n" + " -- Sub Error Code %d\r\n" + " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState); + + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); +} + diff --git a/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.h b/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.h index 95cecca5c..000069620 100644 --- a/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.h +++ b/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/AndroidAccessoryHost.h @@ -1,78 +1,78 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for AndroidAccessoryHost.c. - */ - -#ifndef _ANDROIDACCESSORY_HOST_H_ -#define _ANDROIDACCESSORY_HOST_H_ - - /* Includes: */ - #include - #include - #include - #include - #include - #include - - #include - #include - #include - #include - - /* Macros: */ - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /* Function Prototypes: */ - void SetupHardware(void); - void AOAHost_Task(void); - - void EVENT_USB_Host_HostError(const uint8_t ErrorCode); - void EVENT_USB_Host_DeviceAttached(void); - void EVENT_USB_Host_DeviceUnattached(void); - void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, - const uint8_t SubErrorCode); - void EVENT_USB_Host_DeviceEnumerationComplete(void); - -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for AndroidAccessoryHost.c. + */ + +#ifndef _ANDROIDACCESSORY_HOST_H_ +#define _ANDROIDACCESSORY_HOST_H_ + + /* Includes: */ + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + + /* Macros: */ + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /* Function Prototypes: */ + void SetupHardware(void); + void AOAHost_Task(void); + + void EVENT_USB_Host_HostError(const uint8_t ErrorCode); + void EVENT_USB_Host_DeviceAttached(void); + void EVENT_USB_Host_DeviceUnattached(void); + void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, + const uint8_t SubErrorCode); + void EVENT_USB_Host_DeviceEnumerationComplete(void); + +#endif + diff --git a/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/makefile b/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/makefile index d8d255c4f..2f11b854c 100644 --- a/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/makefile +++ b/trunk/Demos/Host/ClassDriver/AndroidAccessoryHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/AudioInputHost/makefile b/trunk/Demos/Host/ClassDriver/AudioInputHost/makefile index f51574bdc..46916fcc3 100644 --- a/trunk/Demos/Host/ClassDriver/AudioInputHost/makefile +++ b/trunk/Demos/Host/ClassDriver/AudioInputHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/AudioOutputHost/makefile b/trunk/Demos/Host/ClassDriver/AudioOutputHost/makefile index 20d2d85d2..ea54c2e5f 100644 --- a/trunk/Demos/Host/ClassDriver/AudioOutputHost/makefile +++ b/trunk/Demos/Host/ClassDriver/AudioOutputHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/JoystickHostWithParser/makefile b/trunk/Demos/Host/ClassDriver/JoystickHostWithParser/makefile index 6da44b02e..a170830e5 100644 --- a/trunk/Demos/Host/ClassDriver/JoystickHostWithParser/makefile +++ b/trunk/Demos/Host/ClassDriver/JoystickHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/KeyboardHost/makefile b/trunk/Demos/Host/ClassDriver/KeyboardHost/makefile index 21e61af22..fb74d48ee 100644 --- a/trunk/Demos/Host/ClassDriver/KeyboardHost/makefile +++ b/trunk/Demos/Host/ClassDriver/KeyboardHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/KeyboardHostWithParser/makefile b/trunk/Demos/Host/ClassDriver/KeyboardHostWithParser/makefile index 3a2d75084..005a79641 100644 --- a/trunk/Demos/Host/ClassDriver/KeyboardHostWithParser/makefile +++ b/trunk/Demos/Host/ClassDriver/KeyboardHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/MIDIHost/makefile b/trunk/Demos/Host/ClassDriver/MIDIHost/makefile index 98c3caef4..998972556 100644 --- a/trunk/Demos/Host/ClassDriver/MIDIHost/makefile +++ b/trunk/Demos/Host/ClassDriver/MIDIHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/MassStorageHost/makefile b/trunk/Demos/Host/ClassDriver/MassStorageHost/makefile index 93a2eb272..e2835d243 100644 --- a/trunk/Demos/Host/ClassDriver/MassStorageHost/makefile +++ b/trunk/Demos/Host/ClassDriver/MassStorageHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/MouseHost/makefile b/trunk/Demos/Host/ClassDriver/MouseHost/makefile index 0935b8d4d..a20d59d3c 100644 --- a/trunk/Demos/Host/ClassDriver/MouseHost/makefile +++ b/trunk/Demos/Host/ClassDriver/MouseHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/MouseHostWithParser/makefile b/trunk/Demos/Host/ClassDriver/MouseHostWithParser/makefile index c342fa1fb..6bf3ee3bf 100644 --- a/trunk/Demos/Host/ClassDriver/MouseHostWithParser/makefile +++ b/trunk/Demos/Host/ClassDriver/MouseHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/PrinterHost/makefile b/trunk/Demos/Host/ClassDriver/PrinterHost/makefile index c83749c91..f4531fcf4 100644 --- a/trunk/Demos/Host/ClassDriver/PrinterHost/makefile +++ b/trunk/Demos/Host/ClassDriver/PrinterHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/RNDISEthernetHost/makefile b/trunk/Demos/Host/ClassDriver/RNDISEthernetHost/makefile index 1565f773f..30e6bfcea 100644 --- a/trunk/Demos/Host/ClassDriver/RNDISEthernetHost/makefile +++ b/trunk/Demos/Host/ClassDriver/RNDISEthernetHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/StillImageHost/makefile b/trunk/Demos/Host/ClassDriver/StillImageHost/makefile index 29a07dc4c..118778a86 100644 --- a/trunk/Demos/Host/ClassDriver/StillImageHost/makefile +++ b/trunk/Demos/Host/ClassDriver/StillImageHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/ClassDriver/VirtualSerialHost/makefile b/trunk/Demos/Host/ClassDriver/VirtualSerialHost/makefile index e074f8413..6bd3fbe7a 100644 --- a/trunk/Demos/Host/ClassDriver/VirtualSerialHost/makefile +++ b/trunk/Demos/Host/ClassDriver/VirtualSerialHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/AndroidAccessoryHost/makefile b/trunk/Demos/Host/LowLevel/AndroidAccessoryHost/makefile index bd51e8f53..c8da7e08f 100644 --- a/trunk/Demos/Host/LowLevel/AndroidAccessoryHost/makefile +++ b/trunk/Demos/Host/LowLevel/AndroidAccessoryHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/AudioInputHost/makefile b/trunk/Demos/Host/LowLevel/AudioInputHost/makefile index d271e2e46..4f9e8dfae 100644 --- a/trunk/Demos/Host/LowLevel/AudioInputHost/makefile +++ b/trunk/Demos/Host/LowLevel/AudioInputHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/AudioOutputHost/makefile b/trunk/Demos/Host/LowLevel/AudioOutputHost/makefile index 8185200d7..bb73504ef 100644 --- a/trunk/Demos/Host/LowLevel/AudioOutputHost/makefile +++ b/trunk/Demos/Host/LowLevel/AudioOutputHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/GenericHIDHost/makefile b/trunk/Demos/Host/LowLevel/GenericHIDHost/makefile index 15fb5ec11..cbec54a4c 100644 --- a/trunk/Demos/Host/LowLevel/GenericHIDHost/makefile +++ b/trunk/Demos/Host/LowLevel/GenericHIDHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/JoystickHostWithParser/makefile b/trunk/Demos/Host/LowLevel/JoystickHostWithParser/makefile index a3ec3ecf8..6ad028847 100644 --- a/trunk/Demos/Host/LowLevel/JoystickHostWithParser/makefile +++ b/trunk/Demos/Host/LowLevel/JoystickHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/KeyboardHost/makefile b/trunk/Demos/Host/LowLevel/KeyboardHost/makefile index 4b98db4af..fe27ca196 100644 --- a/trunk/Demos/Host/LowLevel/KeyboardHost/makefile +++ b/trunk/Demos/Host/LowLevel/KeyboardHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/KeyboardHostWithParser/makefile b/trunk/Demos/Host/LowLevel/KeyboardHostWithParser/makefile index 05c7e3fa8..4cc47619d 100644 --- a/trunk/Demos/Host/LowLevel/KeyboardHostWithParser/makefile +++ b/trunk/Demos/Host/LowLevel/KeyboardHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/MIDIHost/makefile b/trunk/Demos/Host/LowLevel/MIDIHost/makefile index 4feb22571..a4a347175 100644 --- a/trunk/Demos/Host/LowLevel/MIDIHost/makefile +++ b/trunk/Demos/Host/LowLevel/MIDIHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/MassStorageHost/makefile b/trunk/Demos/Host/LowLevel/MassStorageHost/makefile index 3085cd8ff..0d5520263 100644 --- a/trunk/Demos/Host/LowLevel/MassStorageHost/makefile +++ b/trunk/Demos/Host/LowLevel/MassStorageHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/MouseHost/makefile b/trunk/Demos/Host/LowLevel/MouseHost/makefile index cad2b1c26..dc8c671e4 100644 --- a/trunk/Demos/Host/LowLevel/MouseHost/makefile +++ b/trunk/Demos/Host/LowLevel/MouseHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/MouseHostWithParser/makefile b/trunk/Demos/Host/LowLevel/MouseHostWithParser/makefile index 332bd58eb..d32a20ac7 100644 --- a/trunk/Demos/Host/LowLevel/MouseHostWithParser/makefile +++ b/trunk/Demos/Host/LowLevel/MouseHostWithParser/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/PrinterHost/makefile b/trunk/Demos/Host/LowLevel/PrinterHost/makefile index 54e3cf67b..7269e122b 100644 --- a/trunk/Demos/Host/LowLevel/PrinterHost/makefile +++ b/trunk/Demos/Host/LowLevel/PrinterHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/RNDISEthernetHost/makefile b/trunk/Demos/Host/LowLevel/RNDISEthernetHost/makefile index e9a152a2a..defb5b2e0 100644 --- a/trunk/Demos/Host/LowLevel/RNDISEthernetHost/makefile +++ b/trunk/Demos/Host/LowLevel/RNDISEthernetHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/StillImageHost/makefile b/trunk/Demos/Host/LowLevel/StillImageHost/makefile index 7aaa7beee..67537f036 100644 --- a/trunk/Demos/Host/LowLevel/StillImageHost/makefile +++ b/trunk/Demos/Host/LowLevel/StillImageHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Demos/Host/LowLevel/VirtualSerialHost/makefile b/trunk/Demos/Host/LowLevel/VirtualSerialHost/makefile index 1f2fcbf9f..8346c8d55 100644 --- a/trunk/Demos/Host/LowLevel/VirtualSerialHost/makefile +++ b/trunk/Demos/Host/LowLevel/VirtualSerialHost/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/LUFA.pnproj b/trunk/LUFA.pnproj index 1bdc23af4..df32a1d53 100644 --- a/trunk/LUFA.pnproj +++ b/trunk/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/trunk/LUFA/Build/lufa.atprogram.in b/trunk/LUFA/Build/lufa.atprogram.in index 95b0a9702..f9f5dfc9c 100644 --- a/trunk/LUFA/Build/lufa.atprogram.in +++ b/trunk/LUFA/Build/lufa.atprogram.in @@ -48,9 +48,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables ATPROGRAM_PROGRAMMER ?= jtagice3 diff --git a/trunk/LUFA/Build/lufa.avrdude.in b/trunk/LUFA/Build/lufa.avrdude.in index 1aa85c113..21f93ef26 100644 --- a/trunk/LUFA/Build/lufa.avrdude.in +++ b/trunk/LUFA/Build/lufa.avrdude.in @@ -48,9 +48,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables AVRDUDE_PROGRAMMER ?= jtagicemkii @@ -67,13 +69,16 @@ $(call ERROR_IF_EMPTY, AVRDUDE_PORT) # Output Messages MSG_AVRDUDE_CMD := ' [AVRDUDE] :' +# Construct base avrdude command flags +BASE_AVRDUDE_FLAGS := -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) + avrdude: $(TARGET).hex $(MAKEFILE_LIST) @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" FLASH with settings \"$(AVRDUDE_FLASH_FLAGS)\" using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\" - avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U flash:w:$< $(AVRDUDE_FLAGS) + avrdude $(BASE_AVRDUDE_FLAGS) -U flash:w:$< $(AVRDUDE_FLAGS) avrdude-ee: $(TARGET).eep $(MAKEFILE_LIST) @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" EEPROM with settings \"$(AVRDUDE_EEP_FLAGS)\" using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\" - avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U eeprom:w:$< $(AVRDUDE_FLAGS) + avrdude $(BASE_AVRDUDE_FLAGS) -U eeprom:w:$< $(AVRDUDE_FLAGS) # Phony build targets for this module .PHONY: avrdude avrdude-ee diff --git a/trunk/LUFA/Build/lufa.build.in b/trunk/LUFA/Build/lufa.build.in index 47d3276c4..994f4b7fd 100644 --- a/trunk/LUFA/Build/lufa.build.in +++ b/trunk/LUFA/Build/lufa.build.in @@ -68,9 +68,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables BOARD ?= NONE @@ -99,12 +101,12 @@ $(call ERROR_IF_EMPTY, OBJDIR) # Determine the utility prefix to use for the selected architecture ifeq ($(ARCH), AVR8) - CROSS := avr- + CROSS := avr else ifeq ($(ARCH), XMEGA) - CROSS := avr- + CROSS := avr $(warning The XMEGA device support is currently EXPERIMENTAL (incomplete and/or non-functional), and is included for preview purposes only.) else ifeq ($(ARCH), UC3) - CROSS := avr32- + CROSS := avr32 $(warning The UC3 device support is currently EXPERIMENTAL (incomplete and/or non-functional), and is included for preview purposes only.) else $(error Unsupported architecture "$(ARCH)") @@ -113,8 +115,8 @@ endif # Output Messages MSG_BUILD_BEGIN := Begin compilation of project \"$(TARGET)\"... MSG_BUILD_END := Finished building project \"$(TARGET)\". -MSG_COMPILE_CMD := ' [CC] :' -MSG_ASSEMBLE_CMD := ' [AS] :' +MSG_COMPILE_CMD := ' [GCC] :' +MSG_ASSEMBLE_CMD := ' [GAS] :' MSG_NM_CMD := ' [NM] :' MSG_REMOVE_CMD := ' [RM] :' MSG_LINKER_CMD := ' [LNK] :' @@ -145,7 +147,7 @@ endif DEPENDENCY_FILES = $(OBJECT_FILES:%.o=%.d) # Create a list of common flags to pass to the compiler/linker/assembler -BASE_CC_FLAGS := +BASE_CC_FLAGS := -pipe ifeq ($(ARCH), AVR8) BASE_CC_FLAGS += -mmcu=$(MCU) -gdwarf-2 -fshort-enums -fno-inline-small-functions -fpack-struct else ifeq ($(ARCH), XMEGA) @@ -174,8 +176,8 @@ else endif # Determine flags to pass to the size utility based on its reported features -SIZE_MCU_FLAG := $(shell $(CROSS)size --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) ) -SIZE_FORMAT_FLAG := $(shell $(CROSS)size --help | grep -- --format=.*avr > /dev/null && echo --format=avr ) +SIZE_MCU_FLAG := $(shell $(CROSS)-size --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) ) +SIZE_FORMAT_FLAG := $(shell $(CROSS)-size --help | grep -- --format=.*avr > /dev/null && echo --format=avr ) build_begin: @@ -188,7 +190,7 @@ build_end: @echo "" gcc_version: - @$(CROSS)gcc --version + @$(CROSS)-gcc --version check_source: @for f in $(SRC); do \ @@ -201,7 +203,7 @@ check_source: size: $(TARGET).elf @echo $(MSG_SIZE_CMD) Determining size of \"$<\" @echo "" - $(CROSS)size $(SIZE_MCU_FLAG) $(SIZE_FORMAT_FLAG) $< ; 2>/dev/null; + $(CROSS)-size $(SIZE_MCU_FLAG) $(SIZE_FORMAT_FLAG) $< ; 2>/dev/null; symbol-sizes: $(TARGET).elf @echo $(MSG_NM_CMD) Extracting \"$<\" symbols with decimal byte sizes @@ -224,37 +226,37 @@ sym: $(TARGET).sym $(OBJDIR)/%.o: %.c $(MAKEFILE_LIST) @echo $(MSG_COMPILE_CMD) Compiling C file \"$(notdir $<)\" - $(CROSS)gcc -c $(BASE_CC_FLAGS) $(BASE_C_FLAGS) $(CC_FLAGS) $(C_FLAGS) -MMD -MP -MF $(@:%.o=%.d) $< -o $@ + $(CROSS)-gcc -c $(BASE_CC_FLAGS) $(BASE_C_FLAGS) $(CC_FLAGS) $(C_FLAGS) -MMD -MP -MF $(@:%.o=%.d) $< -o $@ $(OBJDIR)/%.o: %.cpp $(MAKEFILE_LIST) @echo $(MSG_COMPILE_CMD) Compiling C++ file \"$(notdir $<)\" - $(CROSS)gcc -c $(BASE_CC_FLAGS) $(BASE_CPP_FLAGS) $(CC_FLAGS) $(CPP_FLAGS) -MMD -MP -MF $(@:%.o=%.d) $< -o $@ + $(CROSS)-gcc -c $(BASE_CC_FLAGS) $(BASE_CPP_FLAGS) $(CC_FLAGS) $(CPP_FLAGS) -MMD -MP -MF $(@:%.o=%.d) $< -o $@ $(OBJDIR)/%.o: %.S $(MAKEFILE_LIST) @echo $(MSG_ASSEMBLE_CMD) Assembling \"$(notdir $<)\" - $(CROSS)gcc -c $(BASE_CC_FLAGS) $(BASE_ASM_FLAGS) $(CC_FLAGS) $(ASM_FLAGS) $< -o $@ + $(CROSS)-gcc -c $(BASE_CC_FLAGS) $(BASE_ASM_FLAGS) $(CC_FLAGS) $(ASM_FLAGS) $< -o $@ .PRECIOUS : $(OBJECT_FILES) .SECONDARY : %.elf %.elf: $(OBJECT_FILES) @echo $(MSG_LINKER_CMD) Linking object files into \"$@\" - $(CROSS)gcc $(BASE_CC_FLAGS) $(BASE_LD_FLAGS) $(CC_FLAGS) $(LD_FLAGS) $^ -o $@ + $(CROSS)-gcc $(BASE_CC_FLAGS) $(BASE_LD_FLAGS) $(CC_FLAGS) $(LD_FLAGS) $^ -o $@ %.hex: %.elf @echo $(MSG_OBJCPY_CMD) Extracting HEX file data from \"$<\" - $(CROSS)objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ + $(CROSS)-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ %.eep: %.elf @echo $(MSG_OBJCPY_CMD) Extracting EEP file data from \"$<\" - $(CROSS)objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex $< $@ || exit 0 + $(CROSS)-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex $< $@ || exit 0 %.lss: %.elf @echo $(MSG_OBJDMP_CMD) Extracting LSS file data from \"$<\" - $(CROSS)objdump -h -S -z $< > $@ + $(CROSS)-objdump -h -S -z $< > $@ %.sym: %.elf @echo $(MSG_NM_CMD) Extracting SYM file data from \"$<\" - $(CROSS)nm -n $< > $@ + $(CROSS)-nm -n $< > $@ # Include build dependency files -include $(DEPENDENCY_FILES) diff --git a/trunk/LUFA/Build/lufa.core.in b/trunk/LUFA/Build/lufa.core.in index 96b6df366..f44b407ed 100644 --- a/trunk/LUFA/Build/lufa.core.in +++ b/trunk/LUFA/Build/lufa.core.in @@ -51,6 +51,8 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- +SHELL = /bin/sh + # Build sorted and filtered lists of the included build module data SORTED_LUFA_BUILD_MODULES = $(sort $(LUFA_BUILD_MODULES)) SORTED_LUFA_BUILD_TARGETS = $(sort $(LUFA_BUILD_TARGETS)) diff --git a/trunk/LUFA/Build/lufa.cppcheck.in b/trunk/LUFA/Build/lufa.cppcheck.in index 66f3aeef5..1593a4279 100644 --- a/trunk/LUFA/Build/lufa.cppcheck.in +++ b/trunk/LUFA/Build/lufa.cppcheck.in @@ -54,9 +54,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables CPPCHECK_INCLUDES ?= diff --git a/trunk/LUFA/Build/lufa.dfu.in b/trunk/LUFA/Build/lufa.dfu.in index 7eb1fa08e..ba75f14a7 100644 --- a/trunk/LUFA/Build/lufa.dfu.in +++ b/trunk/LUFA/Build/lufa.dfu.in @@ -46,9 +46,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Sanity-check values of mandatory user-supplied variables $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR))) diff --git a/trunk/LUFA/Build/lufa.doxygen.in b/trunk/LUFA/Build/lufa.doxygen.in index 2d8c28db3..baca62f60 100644 --- a/trunk/LUFA/Build/lufa.doxygen.in +++ b/trunk/LUFA/Build/lufa.doxygen.in @@ -45,9 +45,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Default values of optionally user-supplied variables DOXYGEN_CONF ?= Doxygen.conf diff --git a/trunk/LUFA/Build/lufa.hid.in b/trunk/LUFA/Build/lufa.hid.in new file mode 100644 index 000000000..34d1e2b80 --- /dev/null +++ b/trunk/LUFA/Build/lufa.hid.in @@ -0,0 +1,70 @@ +# +# LUFA Library +# Copyright (C) Dean Camera, 2012. +# +# dean [at] fourwalledcubicle [dot] com +# www.lufa-lib.org +# + +LUFA_BUILD_MODULES += HID +LUFA_BUILD_TARGETS += hid hid-teensy +LUFA_BUILD_MANDATORY_VARS += MCU TARGET +LUFA_BUILD_OPTIONAL_VARS += +LUFA_BUILD_PROVIDED_VARS += +LUFA_BUILD_PROVIDED_MACROS += + +# ----------------------------------------------------------------------------- +# LUFA HID Bootloader Buildsystem Makefile Module. +# ----------------------------------------------------------------------------- +# DESCRIPTION: +# Provides a set of targets to re-program a device currently running a HID +# class bootloader with a project's FLASH files. +# ----------------------------------------------------------------------------- +# TARGETS: +# +# hid - Program FLASH into target via +# hid_bootloader_cli +# hid-teensy - Program FLASH into target via +# teensy_loader_cli +# +# MANDATORY PARAMETERS: +# +# MCU - Microcontroller device model name +# TARGET - Application name +# +# OPTIONAL PARAMETERS: +# +# (None) +# +# PROVIDED VARIABLES: +# +# (None) +# +# PROVIDED MACROS: +# +# (None) +# +# ----------------------------------------------------------------------------- + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) + +# Sanity-check values of mandatory user-supplied variables +$(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR))) +$(call ERROR_IF_EMPTY, MCU) +$(call ERROR_IF_EMPTY, TARGET) + +# Output Messages +MSG_HID_BOOTLOADER_CMD := ' [HID] :' + +hid: $(TARGET).hex $(MAKEFILE_LIST) + @echo $(MSG_HID_BOOTLOADER_CMD) Programming FLASH with hid_bootloader_cli using \"$<\" + hid_bootloader_cli -mmcu=$(MCU) -v $< + +hid-teensy: $(TARGET).hex $(MAKEFILE_LIST) + @echo $(MSG_HID_BOOTLOADER_CMD) Programming FLASH with teensy_loader_cli using \"$<\" + teensy_loader_cli -mmcu=$(MCU) -v $< + +# Phony build targets for this module +.PHONY: hid hid-teensy diff --git a/trunk/LUFA/Build/lufa.sources.in b/trunk/LUFA/Build/lufa.sources.in index d5316ba87..a475ece09 100644 --- a/trunk/LUFA/Build/lufa.sources.in +++ b/trunk/LUFA/Build/lufa.sources.in @@ -52,9 +52,11 @@ LUFA_BUILD_PROVIDED_MACROS += # # ----------------------------------------------------------------------------- -ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) -ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) -ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) # Sanity check user supplied values $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR))) diff --git a/trunk/LUFA/CodeTemplates/makefile_template b/trunk/LUFA/CodeTemplates/makefile_template index fd53e3706..cf2b6737c 100644 --- a/trunk/LUFA/CodeTemplates/makefile_template +++ b/trunk/LUFA/CodeTemplates/makefile_template @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/LUFA/DoxygenPages/BuildSystem.txt b/trunk/LUFA/DoxygenPages/BuildSystem.txt index 61087a5ce..5190adf26 100644 --- a/trunk/LUFA/DoxygenPages/BuildSystem.txt +++ b/trunk/LUFA/DoxygenPages/BuildSystem.txt @@ -38,6 +38,7 @@ * \li \subpage Page_BuildModule_CPPCHECK - Static Code Analysis * \li \subpage Page_BuildModule_DFU - Device Programming * \li \subpage Page_BuildModule_DOXYGEN - Automated Source Code Documentation + * \li \subpage Page_BuildModule_HID - Device Programming * \li \subpage Page_BuildModule_SOURCES - LUFA Module Source Code Variables */ @@ -512,7 +513,8 @@ * * The DFU programming utility LUFA build system module, providing targets to reprogram an * Atmel processor FLASH and EEPROM memories with a project's compiled binary output files. - * This module requires a DFU class bootloader to be running in the target. + * This module requires a DFU class bootloader to be running in the target, compatible with + * the DFU bootloader protocol as published by Atmel. * * To use this module in your application makefile, add the following code: * \code @@ -653,6 +655,75 @@ * */ + /** \page Page_BuildModule_HID The HID build module + * + * The HID programming utility LUFA build system module, providing targets to reprogram an + * Atmel processor's FLASH memory with a project's compiled binary output file. This module + * requires a HID class bootloader to be running in the target, using a protocol compatible + * with the PJRC "HalfKay" protocol (http://www.pjrc.com/teensy/halfkay_protocol.html). + * + * To use this module in your application makefile, add the following code: + * \code + * include $(LUFA_PATH)/Build/lufa.hid.in + * \endcode + * + * \section SSec_BuildModule_HID_Requirements Requirements + * This module requires either the hid_bootloader_cli utility from the included LUFA HID + * class bootloader API subdirectory, or the teensy_loader_cli utility from PJRC + * (http://www.pjrc.com/teensy/loader_cli.html) to be available in your system's PATH + * variable. + * + * \section SSec_BuildModule_HID_Targets Targets + * + * + * + * + * + * + * + * + * + * + *
hidProgram the device FLASH memory with the application's executable data using hid_bootloader_cli.
hid-teensyProgram the device FLASH memory with the application's executable data using teensy_loader_cli.
+ * + * \section SSec_BuildModule_HID_MandatoryParams Mandatory Parameters + * + * + * + * + * + * + * + * + * + * + *
MCUName of the Atmel processor model (e.g. at90usb1287).
TARGETName of the application output file prefix (e.g. TestApplication).
+ * + * \section SSec_BuildModule_HID_OptionalParams Optional Parameters + * + * + * + * + * + *
None
+ * + * \section SSec_BuildModule_HID_ProvideVariables Module Provided Variables + * + * + * + * + * + *
None
+ * + * \section SSec_BuildModule_HID_ProvidedMacros Module Provided Macros + * + * + * + * + * + *
None
+ */ + /** \page Page_BuildModule_SOURCES The SOURCES build module * * The SOURCES LUFA build system module, providing variables listing the various LUFA source files diff --git a/trunk/LUFA/Drivers/Board/AVR8/MICROPENDOUS/Buttons.h b/trunk/LUFA/Drivers/Board/AVR8/MICROPENDOUS/Buttons.h index 731d1b05b..60d81b782 100644 --- a/trunk/LUFA/Drivers/Board/AVR8/MICROPENDOUS/Buttons.h +++ b/trunk/LUFA/Drivers/Board/AVR8/MICROPENDOUS/Buttons.h @@ -1,208 +1,208 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Board specific Buttons driver header for the Micropendous series boards. - * \copydetails Group_Buttons_MICROPENDOUS_32U2 - * - * \note This file should not be included directly. It is automatically included as needed by the Buttons driver - * dispatch header located in LUFA/Drivers/Board/Buttons.h. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_A MICROPENDOUS_A - * \brief Board specific Button driver header for the Micropendous A (https://code.google.com/p/micropendous/wiki/MicropendousA). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_1 MICROPENDOUS_1 - * \brief Board specific Button driver header for the Micropendous 1 (https://code.google.com/p/micropendous/wiki/Micropendous1). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_2 MICROPENDOUS_2 - * \brief Board specific Button driver header for the Micropendous 2 (https://code.google.com/p/micropendous/wiki/Micropendous2). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_3 MICROPENDOUS_3 - * \brief Board specific Button driver header for the Micropendous 3 (https://code.google.com/p/micropendous/wiki/Micropendous3). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_4 MICROPENDOUS_4 - * \brief Board specific Button driver header for the Micropendous 4 (https://code.google.com/p/micropendous/wiki/Micropendous4). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_DIP MICROPENDOUS_DIP - * \brief Board specific Button driver header for the Micropendous DIP (https://code.google.com/p/micropendous/wiki/MicropendousDIP). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_REV1 MICROPENDOUS_REV1 - * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 1 (https://code.google.com/p/micropendous/wiki/Micropendous). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_REV2 MICROPENDOUS_REV2 - * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 2 (https://code.google.com/p/micropendous/wiki/Micropendous). - * - * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_MICROPENDOUS_32U2 MICROPENDOUS_32U2 - * \brief Board specific Buttons driver header for the Micropendous 32U2. - * - * \note There are multiple supported Micropendous boards, compile with BOARD = MICROPENDOUS_{VERSION}. - * - * Board specific Buttons driver header for the Micropendous 32U2 (https://code.google.com/p/micropendous/wiki/Micropendous_32U2). - * - * BOARD_MICROPENDOUS_1 and BOARD_MICROPENDOUS_32U2: - * - * - * - *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTD.7
- * - * Other Revisions: - * - * - * - *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTE.2
- * - * @{ - */ - -#ifndef __BUTTONS_MICROPENDOUS_H__ -#define __BUTTONS_MICROPENDOUS_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_BUTTONS_H) - #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. - #endif - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - #if (BOARD == BOARD_MICROPENDOUS_32U2) - #define _BOARD_BUTTON1_MASK (1 << 7) - #define _BOARD_BUTTON_PORTLETTER D - #elif (BOARD == BOARD_MICROPENDOUS_A) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_1) - #define _BOARD_BUTTON1_MASK (1 << 7) - #define _BOARD_BUTTON_PORTLETTER D - #elif (BOARD == BOARD_MICROPENDOUS_2) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_3) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_4) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_DIP) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_REV1) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #elif (BOARD == BOARD_MICROPENDOUS_REV2) - #define _BOARD_BUTTON1_MASK (1 << 2) - #define _BOARD_BUTTON_PORTLETTER E - #endif - - #define _BOARD_BUTTON_CONCAT2(Reg, Letter) Reg ## Letter - #define _BOARD_BUTTON_CONCAT(Reg, Letter) _BOARD_BUTTON_CONCAT2(Reg, Letter) - - #define _BOARD_BUTTON_PORT _BOARD_BUTTON_CONCAT(PORT, _BOARD_BUTTON_PORTLETTER) - #define _BOARD_BUTTON_PIN _BOARD_BUTTON_CONCAT(PIN, _BOARD_BUTTON_PORTLETTER) - #define _BOARD_BUTTON_DDR _BOARD_BUTTON_CONCAT(DDR, _BOARD_BUTTON_PORTLETTER) - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Button mask for the first button on the board. */ - #define BUTTONS_BUTTON1 _BOARD_BUTTON1_MASK - - /* Inline Functions: */ - #if !defined(__DOXYGEN__) - static inline void Buttons_Init(void) - { - _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1; - _BOARD_BUTTON_PORT |= BUTTONS_BUTTON1; - } - - static inline void Buttons_Disable(void) - { - _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1; - _BOARD_BUTTON_PORT &= ~BUTTONS_BUTTON1; - } - - static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; - static inline uint8_t Buttons_GetStatus(void) - { - return ((_BOARD_BUTTON_PIN & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1); - } - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific Buttons driver header for the Micropendous series boards. + * \copydetails Group_Buttons_MICROPENDOUS_32U2 + * + * \note This file should not be included directly. It is automatically included as needed by the Buttons driver + * dispatch header located in LUFA/Drivers/Board/Buttons.h. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_A MICROPENDOUS_A + * \brief Board specific Button driver header for the Micropendous A (https://code.google.com/p/micropendous/wiki/MicropendousA). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_1 MICROPENDOUS_1 + * \brief Board specific Button driver header for the Micropendous 1 (https://code.google.com/p/micropendous/wiki/Micropendous1). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_2 MICROPENDOUS_2 + * \brief Board specific Button driver header for the Micropendous 2 (https://code.google.com/p/micropendous/wiki/Micropendous2). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_3 MICROPENDOUS_3 + * \brief Board specific Button driver header for the Micropendous 3 (https://code.google.com/p/micropendous/wiki/Micropendous3). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_4 MICROPENDOUS_4 + * \brief Board specific Button driver header for the Micropendous 4 (https://code.google.com/p/micropendous/wiki/Micropendous4). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_DIP MICROPENDOUS_DIP + * \brief Board specific Button driver header for the Micropendous DIP (https://code.google.com/p/micropendous/wiki/MicropendousDIP). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_REV1 MICROPENDOUS_REV1 + * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 1 (https://code.google.com/p/micropendous/wiki/Micropendous). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_REV2 MICROPENDOUS_REV2 + * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 2 (https://code.google.com/p/micropendous/wiki/Micropendous). + * + * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_MICROPENDOUS_32U2 MICROPENDOUS_32U2 + * \brief Board specific Buttons driver header for the Micropendous 32U2. + * + * \note There are multiple supported Micropendous boards, compile with BOARD = MICROPENDOUS_{VERSION}. + * + * Board specific Buttons driver header for the Micropendous 32U2 (https://code.google.com/p/micropendous/wiki/Micropendous_32U2). + * + * BOARD_MICROPENDOUS_1 and BOARD_MICROPENDOUS_32U2: + * + * + * + *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTD.7
+ * + * Other Revisions: + * + * + * + *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTE.2
+ * + * @{ + */ + +#ifndef __BUTTONS_MICROPENDOUS_H__ +#define __BUTTONS_MICROPENDOUS_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_BUTTONS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + #if (BOARD == BOARD_MICROPENDOUS_32U2) + #define _BOARD_BUTTON1_MASK (1 << 7) + #define _BOARD_BUTTON_PORTLETTER D + #elif (BOARD == BOARD_MICROPENDOUS_A) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_1) + #define _BOARD_BUTTON1_MASK (1 << 7) + #define _BOARD_BUTTON_PORTLETTER D + #elif (BOARD == BOARD_MICROPENDOUS_2) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_3) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_4) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_DIP) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_REV1) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #elif (BOARD == BOARD_MICROPENDOUS_REV2) + #define _BOARD_BUTTON1_MASK (1 << 2) + #define _BOARD_BUTTON_PORTLETTER E + #endif + + #define _BOARD_BUTTON_CONCAT2(Reg, Letter) Reg ## Letter + #define _BOARD_BUTTON_CONCAT(Reg, Letter) _BOARD_BUTTON_CONCAT2(Reg, Letter) + + #define _BOARD_BUTTON_PORT _BOARD_BUTTON_CONCAT(PORT, _BOARD_BUTTON_PORTLETTER) + #define _BOARD_BUTTON_PIN _BOARD_BUTTON_CONCAT(PIN, _BOARD_BUTTON_PORTLETTER) + #define _BOARD_BUTTON_DDR _BOARD_BUTTON_CONCAT(DDR, _BOARD_BUTTON_PORTLETTER) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Button mask for the first button on the board. */ + #define BUTTONS_BUTTON1 _BOARD_BUTTON1_MASK + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Buttons_Init(void) + { + _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1; + _BOARD_BUTTON_PORT |= BUTTONS_BUTTON1; + } + + static inline void Buttons_Disable(void) + { + _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1; + _BOARD_BUTTON_PORT &= ~BUTTONS_BUTTON1; + } + + static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Buttons_GetStatus(void) + { + return ((_BOARD_BUTTON_PIN & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/trunk/LUFA/Drivers/Board/AVR8/USB2AX/Buttons.h b/trunk/LUFA/Drivers/Board/AVR8/USB2AX/Buttons.h index 73d05a5b3..cb0eecdf6 100644 --- a/trunk/LUFA/Drivers/Board/AVR8/USB2AX/Buttons.h +++ b/trunk/LUFA/Drivers/Board/AVR8/USB2AX/Buttons.h @@ -1,113 +1,113 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX. - * \copydetails Group_Buttons_USB2AX - * - * \note This file should not be included directly. It is automatically included as needed by the Buttons driver - * dispatch header located in LUFA/Drivers/Board/Buttons.h. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_USB2AX_V3 USB2AX_V3 - * \brief Board specific Button driver header for the Paranoid Studio USB2AX revision 3. - * - * See \ref Group_Buttons_USB2AX for more details. - */ - -/** \ingroup Group_Buttons - * \defgroup Group_Buttons_USB2AX USB2AX - * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX. - * - * \note For version 3 USB2AX boards, compile with BOARD = USB2AX_V3. - * - * Board specific Buttons driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX). - * - * - * - * - *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTD.7
- * - * @{ - */ - -#ifndef __BUTTONS_USB2AX_H__ -#define __BUTTONS_USB2AX_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_BUTTONS_H) - #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Button mask for the first button on the board. */ - #define BUTTONS_BUTTON1 (1 << 7) - - /* Inline Functions: */ - #if !defined(__DOXYGEN__) - static inline void Buttons_Init(void) - { - DDRD &= ~BUTTONS_BUTTON1; - PORTD |= BUTTONS_BUTTON1; - } - - static inline void Buttons_Disable(void) - { - DDRD &= ~BUTTONS_BUTTON1; - PORTD &= ~BUTTONS_BUTTON1; - } - - static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; - static inline uint8_t Buttons_GetStatus(void) - { - return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1); - } - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX. + * \copydetails Group_Buttons_USB2AX + * + * \note This file should not be included directly. It is automatically included as needed by the Buttons driver + * dispatch header located in LUFA/Drivers/Board/Buttons.h. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_USB2AX_V3 USB2AX_V3 + * \brief Board specific Button driver header for the Paranoid Studio USB2AX revision 3. + * + * See \ref Group_Buttons_USB2AX for more details. + */ + +/** \ingroup Group_Buttons + * \defgroup Group_Buttons_USB2AX USB2AX + * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX. + * + * \note For version 3 USB2AX boards, compile with BOARD = USB2AX_V3. + * + * Board specific Buttons driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX). + * + * + * + * + *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1HWB ButtonLowPORTD.7
+ * + * @{ + */ + +#ifndef __BUTTONS_USB2AX_H__ +#define __BUTTONS_USB2AX_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_BUTTONS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Button mask for the first button on the board. */ + #define BUTTONS_BUTTON1 (1 << 7) + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Buttons_Init(void) + { + DDRD &= ~BUTTONS_BUTTON1; + PORTD |= BUTTONS_BUTTON1; + } + + static inline void Buttons_Disable(void) + { + DDRD &= ~BUTTONS_BUTTON1; + PORTD &= ~BUTTONS_BUTTON1; + } + + static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t Buttons_GetStatus(void) + { + return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/trunk/LUFA/Drivers/Board/AVR8/USB2AX/LEDs.h b/trunk/LUFA/Drivers/Board/AVR8/USB2AX/LEDs.h index 12fa73cd1..364c88de2 100644 --- a/trunk/LUFA/Drivers/Board/AVR8/USB2AX/LEDs.h +++ b/trunk/LUFA/Drivers/Board/AVR8/USB2AX/LEDs.h @@ -1,196 +1,196 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Board specific LED driver header for the Paranoid Studio USB2AX. - * \copydetails Group_LEDs_USB2AX - * - * \note This file should not be included directly. It is automatically included as needed by the LEDs driver - * dispatch header located in LUFA/Drivers/Board/LEDs.h. - */ - -/** \ingroup Group_LEDs - * \defgroup Group_LEDs_USB2AX_V3 USB2AX_V3 - * \brief Board specific LED driver header for the Paranoid Studio USB2AX revision 3. - * - * See \ref Group_LEDs_USB2AX for more details. - */ - -/** \ingroup Group_LEDs - * \defgroup Group_LEDs_USB2AX USB2AX - * \brief Board specific LED driver header for the Paranoid Studio USB2AX. - * - * \note For version 3 USB2AX boards, compile with BOARD = USB2AX_V3. - * - * Board specific LED driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX). - * - * USB2AX: - * - * - * - *
NameColorInfoActive LevelPort Pin
LEDS_LED1GreenGeneral IndicatorHighPORTC.6
- * - * USB2AX_V3: - * - * - * - *
NameColorInfoActive LevelPort Pin
LEDS_LED1GreenGeneral IndicatorHighPORTD.1
- * - * @{ - */ - -#ifndef __LEDS_USB2AX_H__ -#define __LEDS_USB2AX_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_LEDS_H) - #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead. - #endif - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - /* Macros: */ - #if (BOARD == BOARD_USB2AX) - #define USB2AX_LEDS_LED1 (1 << 6) - #else - #define USB2AX_LEDS_LED1 (1 << 1) - #endif - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** LED mask for the first LED on the board. */ - #define LEDS_LED1 USB2AX_LEDS_LED1 - - /** LED mask for all the LEDs on the board. */ - #define LEDS_ALL_LEDS LEDS_LED1 - - /** LED mask for none of the board LEDs. */ - #define LEDS_NO_LEDS 0 - - /* Inline Functions: */ - #if !defined(__DOXYGEN__) - static inline void LEDs_Init(void) - { - #if (BOARD == BOARD_USB2AX) - DDRC |= LEDS_ALL_LEDS; - PORTC &= ~LEDS_ALL_LEDS; - #else - DDRD |= LEDS_ALL_LEDS; - PORTD &= ~LEDS_ALL_LEDS; - #endif - } - - static inline void LEDs_Disable(void) - { - #if (BOARD == BOARD_USB2AX) - DDRC &= ~LEDS_ALL_LEDS; - PORTC &= ~LEDS_ALL_LEDS; - #else - DDRD &= ~LEDS_ALL_LEDS; - PORTD &= ~LEDS_ALL_LEDS; - #endif - } - - static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) - { - #if (BOARD == BOARD_USB2AX) - PORTC |= LEDMask; - #else - PORTD |= LEDMask; - #endif - } - - static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) - { - #if (BOARD == BOARD_USB2AX) - PORTC &= ~LEDMask; - #else - PORTD &= ~LEDMask; - #endif - } - - static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) - { - #if (BOARD == BOARD_USB2AX) - PORTC = ((PORTC & ~LEDS_ALL_LEDS) | LEDMask); - #else - PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask); - #endif - } - - static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, - const uint8_t ActiveMask) - { - #if (BOARD == BOARD_USB2AX) - PORTC = ((PORTC & ~LEDMask) | ActiveMask); - #else - PORTD = ((PORTD & ~LEDMask) | ActiveMask); - #endif - } - - static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) - { - #if (BOARD == BOARD_USB2AX) - PINC = LEDMask; - #else - PIND = LEDMask; - #endif - } - - static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; - static inline uint8_t LEDs_GetLEDs(void) - { - #if (BOARD == BOARD_USB2AX) - return (PORTC & LEDS_ALL_LEDS); - #else - return (PORTD & LEDS_ALL_LEDS); - #endif - } - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific LED driver header for the Paranoid Studio USB2AX. + * \copydetails Group_LEDs_USB2AX + * + * \note This file should not be included directly. It is automatically included as needed by the LEDs driver + * dispatch header located in LUFA/Drivers/Board/LEDs.h. + */ + +/** \ingroup Group_LEDs + * \defgroup Group_LEDs_USB2AX_V3 USB2AX_V3 + * \brief Board specific LED driver header for the Paranoid Studio USB2AX revision 3. + * + * See \ref Group_LEDs_USB2AX for more details. + */ + +/** \ingroup Group_LEDs + * \defgroup Group_LEDs_USB2AX USB2AX + * \brief Board specific LED driver header for the Paranoid Studio USB2AX. + * + * \note For version 3 USB2AX boards, compile with BOARD = USB2AX_V3. + * + * Board specific LED driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX). + * + * USB2AX: + * + * + * + *
NameColorInfoActive LevelPort Pin
LEDS_LED1GreenGeneral IndicatorHighPORTC.6
+ * + * USB2AX_V3: + * + * + * + *
NameColorInfoActive LevelPort Pin
LEDS_LED1GreenGeneral IndicatorHighPORTD.1
+ * + * @{ + */ + +#ifndef __LEDS_USB2AX_H__ +#define __LEDS_USB2AX_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_LEDS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #if (BOARD == BOARD_USB2AX) + #define USB2AX_LEDS_LED1 (1 << 6) + #else + #define USB2AX_LEDS_LED1 (1 << 1) + #endif + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** LED mask for the first LED on the board. */ + #define LEDS_LED1 USB2AX_LEDS_LED1 + + /** LED mask for all the LEDs on the board. */ + #define LEDS_ALL_LEDS LEDS_LED1 + + /** LED mask for none of the board LEDs. */ + #define LEDS_NO_LEDS 0 + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void LEDs_Init(void) + { + #if (BOARD == BOARD_USB2AX) + DDRC |= LEDS_ALL_LEDS; + PORTC &= ~LEDS_ALL_LEDS; + #else + DDRD |= LEDS_ALL_LEDS; + PORTD &= ~LEDS_ALL_LEDS; + #endif + } + + static inline void LEDs_Disable(void) + { + #if (BOARD == BOARD_USB2AX) + DDRC &= ~LEDS_ALL_LEDS; + PORTC &= ~LEDS_ALL_LEDS; + #else + DDRD &= ~LEDS_ALL_LEDS; + PORTD &= ~LEDS_ALL_LEDS; + #endif + } + + static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) + { + #if (BOARD == BOARD_USB2AX) + PORTC |= LEDMask; + #else + PORTD |= LEDMask; + #endif + } + + static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) + { + #if (BOARD == BOARD_USB2AX) + PORTC &= ~LEDMask; + #else + PORTD &= ~LEDMask; + #endif + } + + static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) + { + #if (BOARD == BOARD_USB2AX) + PORTC = ((PORTC & ~LEDS_ALL_LEDS) | LEDMask); + #else + PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask); + #endif + } + + static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, + const uint8_t ActiveMask) + { + #if (BOARD == BOARD_USB2AX) + PORTC = ((PORTC & ~LEDMask) | ActiveMask); + #else + PORTD = ((PORTD & ~LEDMask) | ActiveMask); + #endif + } + + static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) + { + #if (BOARD == BOARD_USB2AX) + PINC = LEDMask; + #else + PIND = LEDMask; + #endif + } + + static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; + static inline uint8_t LEDs_GetLEDs(void) + { + #if (BOARD == BOARD_USB2AX) + return (PORTC & LEDS_ALL_LEDS); + #else + return (PORTD & LEDS_ALL_LEDS); + #endif + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/trunk/LUFA/Drivers/USB/Class/AndroidAccessoryClass.h b/trunk/LUFA/Drivers/USB/Class/AndroidAccessoryClass.h index 3cede6026..7b1fbfcc2 100644 --- a/trunk/LUFA/Drivers/USB/Class/AndroidAccessoryClass.h +++ b/trunk/LUFA/Drivers/USB/Class/AndroidAccessoryClass.h @@ -1,76 +1,76 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Master include file for the library USB Android Open Accessory Class driver. - * - * Master include file for the library USB Android Open Accessory Class driver, for both host and device modes, where available. - * - * This file should be included in all user projects making use of this optional class driver, instead of - * including any headers in the USB/ClassDriver/Device, USB/ClassDriver/Host or USB/ClassDriver/Common subdirectories. - */ - -/** \ingroup Group_USBClassDrivers - * \defgroup Group_USBClassAOA Android Open Accessory Class Driver - * - * \section Sec_Dependencies Module Source Dependencies - * The following files must be built with any user project that uses this module: - * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) - * - * \section Sec_ModDescription Module Description - * Android Open Accessory Class Driver module. This module contains an internal implementation of the USB Android Open Accessory - * Class, for Host USB mode. User applications can use this class driver instead of implementing the Android Open Accessory Class - * manually via the low-level LUFA APIs. - * - * This module is designed to simplify the user code by exposing only the required interface needed to interface with - * Host using the USB Android Open Accessory Class. - * - * @{ - */ - -#ifndef _AOA_CLASS_H_ -#define _AOA_CLASS_H_ - - /* Macros: */ - #define __INCLUDE_FROM_USB_DRIVER - #define __INCLUDE_FROM_AOA_DRIVER - - /* Includes: */ - #include "../Core/USBMode.h" - - #if defined(USB_CAN_BE_HOST) - #include "Host/AndroidAccessoryClassHost.h" - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Master include file for the library USB Android Open Accessory Class driver. + * + * Master include file for the library USB Android Open Accessory Class driver, for both host and device modes, where available. + * + * This file should be included in all user projects making use of this optional class driver, instead of + * including any headers in the USB/ClassDriver/Device, USB/ClassDriver/Host or USB/ClassDriver/Common subdirectories. + */ + +/** \ingroup Group_USBClassDrivers + * \defgroup Group_USBClassAOA Android Open Accessory Class Driver + * + * \section Sec_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) + * + * \section Sec_ModDescription Module Description + * Android Open Accessory Class Driver module. This module contains an internal implementation of the USB Android Open Accessory + * Class, for Host USB mode. User applications can use this class driver instead of implementing the Android Open Accessory Class + * manually via the low-level LUFA APIs. + * + * This module is designed to simplify the user code by exposing only the required interface needed to interface with + * Host using the USB Android Open Accessory Class. + * + * @{ + */ + +#ifndef _AOA_CLASS_H_ +#define _AOA_CLASS_H_ + + /* Macros: */ + #define __INCLUDE_FROM_USB_DRIVER + #define __INCLUDE_FROM_AOA_DRIVER + + /* Includes: */ + #include "../Core/USBMode.h" + + #if defined(USB_CAN_BE_HOST) + #include "Host/AndroidAccessoryClassHost.h" + #endif + +#endif + +/** @} */ + diff --git a/trunk/LUFA/Drivers/USB/Class/Common/AndroidAccessoryClassCommon.h b/trunk/LUFA/Drivers/USB/Class/Common/AndroidAccessoryClassCommon.h index c1c0e8df0..dc1289da6 100644 --- a/trunk/LUFA/Drivers/USB/Class/Common/AndroidAccessoryClassCommon.h +++ b/trunk/LUFA/Drivers/USB/Class/Common/AndroidAccessoryClassCommon.h @@ -1,128 +1,128 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Common definitions and declarations for the library USB Android Open Accessory Class driver. - * - * Common definitions and declarations for the library USB Android Open Accessory Class driver. - * - * \note This file should not be included directly. It is automatically included as needed by the USB module driver - * dispatch header located in LUFA/Drivers/USB.h. - */ - -/** \ingroup Group_USBClassAOA - * \defgroup Group_USBClassAOACommon Common Class Definitions - * - * \section Sec_ModDescription Module Description - * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB - * Android Open Accessory Class. - * - * @{ - */ - -#ifndef _AOA_CLASS_COMMON_H_ -#define _AOA_CLASS_COMMON_H_ - - /* Includes: */ - #include "../../Core/StdDescriptors.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_AOA_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. - #endif - - /* Macros: */ - /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory mode. */ - #define ANDROID_ACCESSORY_PRODUCT_ID 0x2D00 - - /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory and Android Debug mode. */ - #define ANDROID_ACCESSORY_ADB_PRODUCT_ID 0x2D01 - - /* Enums: */ - /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the - * Android Open Accessory class. - */ - enum AOA_Descriptor_ClassSubclassProtocol_t - { - AOA_CSCP_AOADataClass = 0xFF, /**< Descriptor Class value indicating that the device or interface - * belongs to the AOA data class. - */ - AOA_CSCP_AOADataSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device or interface - * belongs to AOA data subclass. - */ - AOA_CSCP_AOADataProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface - * belongs to the AOA data class protocol. - */ - }; - - /** Enum for the Android Open Accessory class specific control requests that can be issued by the USB bus host. */ - enum AOA_ClassRequests_t - { - AOA_REQ_GetAccessoryProtocol = 0x33, /**< Android Open Accessory control request to retrieve the device's supported Accessory Protocol version. */ - AOA_REQ_SendString = 0x34, /**< Android Open Accessory control request to set an accessory property string in the device. */ - AOA_REQ_StartAccessoryMode = 0x35, /**< Android Open Accessory control request to switch the device into Accessory mode. */ - }; - - /** Enum for the possible Android Open Accessory property string indexes. */ - enum AOA_Strings_t - { - AOA_STRING_Manufacturer = 0, /**< Index of the Manufacturer property string. */ - AOA_STRING_Model = 1, /**< Index of the Model Name property string. */ - AOA_STRING_Description = 2, /**< Index of the Description property string. */ - AOA_STRING_Version = 3, /**< Index of the Version Number property string. */ - AOA_STRING_URI = 4, /**< Index of the URI Information property string. */ - AOA_STRING_Serial = 5, /**< Index of the Serial Number property string. */ - - #if !defined(__DOXYGEN__) - AOA_STRING_TOTAL_STRINGS - #endif - }; - - /** Enum for the possible Android Open Accessory protocol versions. */ - enum AOA_Protocols_t - { - AOA_PROTOCOL_AccessoryV1 = 0x0001, /**< Android Open Accessory version 1. */ - }; - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Common definitions and declarations for the library USB Android Open Accessory Class driver. + * + * Common definitions and declarations for the library USB Android Open Accessory Class driver. + * + * \note This file should not be included directly. It is automatically included as needed by the USB module driver + * dispatch header located in LUFA/Drivers/USB.h. + */ + +/** \ingroup Group_USBClassAOA + * \defgroup Group_USBClassAOACommon Common Class Definitions + * + * \section Sec_ModDescription Module Description + * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB + * Android Open Accessory Class. + * + * @{ + */ + +#ifndef _AOA_CLASS_COMMON_H_ +#define _AOA_CLASS_COMMON_H_ + + /* Includes: */ + #include "../../Core/StdDescriptors.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_AOA_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #endif + + /* Macros: */ + /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory mode. */ + #define ANDROID_ACCESSORY_PRODUCT_ID 0x2D00 + + /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory and Android Debug mode. */ + #define ANDROID_ACCESSORY_ADB_PRODUCT_ID 0x2D01 + + /* Enums: */ + /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the + * Android Open Accessory class. + */ + enum AOA_Descriptor_ClassSubclassProtocol_t + { + AOA_CSCP_AOADataClass = 0xFF, /**< Descriptor Class value indicating that the device or interface + * belongs to the AOA data class. + */ + AOA_CSCP_AOADataSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device or interface + * belongs to AOA data subclass. + */ + AOA_CSCP_AOADataProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface + * belongs to the AOA data class protocol. + */ + }; + + /** Enum for the Android Open Accessory class specific control requests that can be issued by the USB bus host. */ + enum AOA_ClassRequests_t + { + AOA_REQ_GetAccessoryProtocol = 0x33, /**< Android Open Accessory control request to retrieve the device's supported Accessory Protocol version. */ + AOA_REQ_SendString = 0x34, /**< Android Open Accessory control request to set an accessory property string in the device. */ + AOA_REQ_StartAccessoryMode = 0x35, /**< Android Open Accessory control request to switch the device into Accessory mode. */ + }; + + /** Enum for the possible Android Open Accessory property string indexes. */ + enum AOA_Strings_t + { + AOA_STRING_Manufacturer = 0, /**< Index of the Manufacturer property string. */ + AOA_STRING_Model = 1, /**< Index of the Model Name property string. */ + AOA_STRING_Description = 2, /**< Index of the Description property string. */ + AOA_STRING_Version = 3, /**< Index of the Version Number property string. */ + AOA_STRING_URI = 4, /**< Index of the URI Information property string. */ + AOA_STRING_Serial = 5, /**< Index of the Serial Number property string. */ + + #if !defined(__DOXYGEN__) + AOA_STRING_TOTAL_STRINGS + #endif + }; + + /** Enum for the possible Android Open Accessory protocol versions. */ + enum AOA_Protocols_t + { + AOA_PROTOCOL_AccessoryV1 = 0x0001, /**< Android Open Accessory version 1. */ + }; + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/trunk/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c b/trunk/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c index 7c564e012..f71fa2b95 100644 --- a/trunk/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c +++ b/trunk/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c @@ -1,422 +1,422 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#define __INCLUDE_FROM_USB_DRIVER -#include "../../Core/USBMode.h" - -#if defined(USB_CAN_BE_HOST) - -#define __INCLUDE_FROM_AOA_DRIVER -#define __INCLUDE_FROM_ANDROIDACCESSORY_HOST_C -#include "AndroidAccessoryClassHost.h" - -bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const USB_Descriptor_Device_t* const DeviceDescriptor, - bool* const NeedModeSwitch) -{ - (void)AOAInterfaceInfo; - - if (DeviceDescriptor->Header.Type != DTYPE_Device) - return false; - - *NeedModeSwitch = ((DeviceDescriptor->ProductID != ANDROID_ACCESSORY_PRODUCT_ID) && - (DeviceDescriptor->ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID)); - - return true; -} - -uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - uint16_t ConfigDescriptorSize, - void* ConfigDescriptorData) -{ - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; - USB_Descriptor_Interface_t* AOAInterface = NULL; - - memset(&AOAInterfaceInfo->State, 0x00, sizeof(AOAInterfaceInfo->State)); - - if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration) - return AOA_ENUMERROR_InvalidConfigDescriptor; - - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - DCOMP_AOA_Host_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - return AOA_ENUMERROR_NoCompatibleInterfaceFound; - } - - AOAInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t); - - while (!(DataINEndpoint) || !(DataOUTEndpoint)) - { - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - DCOMP_AOA_Host_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) - { - return AOA_ENUMERROR_NoCompatibleInterfaceFound; - } - - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); - - if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN) - DataINEndpoint = EndpointData; - else - DataOUTEndpoint = EndpointData; - } - - AOAInterfaceInfo->Config.DataINPipe.Size = le16_to_cpu(DataINEndpoint->EndpointSize); - AOAInterfaceInfo->Config.DataINPipe.EndpointAddress = DataINEndpoint->EndpointAddress; - AOAInterfaceInfo->Config.DataINPipe.Type = EP_TYPE_BULK; - - AOAInterfaceInfo->Config.DataOUTPipe.Size = le16_to_cpu(DataOUTEndpoint->EndpointSize); - AOAInterfaceInfo->Config.DataOUTPipe.EndpointAddress = DataOUTEndpoint->EndpointAddress; - AOAInterfaceInfo->Config.DataOUTPipe.Type = EP_TYPE_BULK; - - if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataINPipe, 1))) - return false; - - if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataOUTPipe, 1))) - return false; - - AOAInterfaceInfo->State.IsActive = true; - AOAInterfaceInfo->State.InterfaceNumber = AOAInterface->InterfaceNumber; - - return AOA_ENUMERROR_NoError; -} - -static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor) -{ - USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); - - if (Header->Type == DTYPE_Interface) - { - USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t); - - if ((Interface->Class == AOA_CSCP_AOADataClass) && - (Interface->SubClass == AOA_CSCP_AOADataSubclass) && - (Interface->Protocol == AOA_CSCP_AOADataProtocol)) - { - return DESCRIPTOR_SEARCH_Found; - } - } - - return DESCRIPTOR_SEARCH_NotFound; -} - -static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) -{ - USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); - - if (Header->Type == DTYPE_Endpoint) - { - USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t); - - uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK); - - if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress)))) - return DESCRIPTOR_SEARCH_Found; - } - else if (Header->Type == DTYPE_Interface) - { - return DESCRIPTOR_SEARCH_Fail; - } - - return DESCRIPTOR_SEARCH_NotFound; -} - -void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return; - - #if !defined(NO_CLASS_DRIVER_AUTOFLUSH) - AOA_Host_Flush(AOAInterfaceInfo); - #endif -} - -uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - uint8_t ErrorCode; - - uint16_t AccessoryProtocol; - if ((ErrorCode = AOA_Host_GetAccessoryProtocol(&AccessoryProtocol)) != HOST_WAITERROR_Successful) - return ErrorCode; - - if (AccessoryProtocol != CPU_TO_LE16(AOA_PROTOCOL_AccessoryV1)) - return AOA_ERROR_LOGICAL_CMD_FAILED; - - for (uint8_t PropertyIndex = 0; PropertyIndex < AOA_STRING_TOTAL_STRINGS; PropertyIndex++) - { - if ((ErrorCode = AOA_Host_SendPropertyString(AOAInterfaceInfo, PropertyIndex)) != HOST_WAITERROR_Successful) - return ErrorCode; - } - - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE), - .bRequest = AOA_REQ_StartAccessoryMode, - .wValue = 0, - .wIndex = 0, - .wLength = 0, - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - return USB_Host_SendControlRequest(NULL); -} - -static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) -{ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE), - .bRequest = AOA_REQ_GetAccessoryProtocol, - .wValue = 0, - .wIndex = 0, - .wLength = sizeof(uint16_t), - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - return USB_Host_SendControlRequest(Protocol); -} - -static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t StringIndex) -{ - const char* String = AOAInterfaceInfo->Config.PropertyStrings[StringIndex]; - - if (String == NULL) - String = ""; - - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE), - .bRequest = AOA_REQ_SendString, - .wValue = 0, - .wIndex = StringIndex, - .wLength = (strlen(String) + 1), - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - return USB_Host_SendControlRequest((char*)String); -} - -uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t* const Buffer, - const uint16_t Length) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return PIPE_READYWAIT_DeviceDisconnected; - - uint8_t ErrorCode; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); - - Pipe_Unfreeze(); - ErrorCode = Pipe_Write_Stream_LE(Buffer, Length, NULL); - Pipe_Freeze(); - - return ErrorCode; -} - -uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const char* const String) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return PIPE_READYWAIT_DeviceDisconnected; - - uint8_t ErrorCode; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); - - Pipe_Unfreeze(); - ErrorCode = Pipe_Write_Stream_LE(String, strlen(String), NULL); - Pipe_Freeze(); - - return ErrorCode; -} - -uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t Data) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return PIPE_READYWAIT_DeviceDisconnected; - - uint8_t ErrorCode; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); - Pipe_Unfreeze(); - - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearOUT(); - - if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) - return ErrorCode; - } - - Pipe_Write_8(Data); - Pipe_Freeze(); - - return PIPE_READYWAIT_NoError; -} - -uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return 0; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address); - Pipe_Unfreeze(); - - if (Pipe_IsINReceived()) - { - if (!(Pipe_BytesInPipe())) - { - Pipe_ClearIN(); - Pipe_Freeze(); - return 0; - } - else - { - Pipe_Freeze(); - return Pipe_BytesInPipe(); - } - } - else - { - Pipe_Freeze(); - - return 0; - } -} - -int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return -1; - - int16_t ReceivedByte = -1; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address); - Pipe_Unfreeze(); - - if (Pipe_IsINReceived()) - { - if (Pipe_BytesInPipe()) - ReceivedByte = Pipe_Read_8(); - - if (!(Pipe_BytesInPipe())) - Pipe_ClearIN(); - } - - Pipe_Freeze(); - - return ReceivedByte; -} - -uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) -{ - if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) - return PIPE_READYWAIT_DeviceDisconnected; - - uint8_t ErrorCode; - - Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); - Pipe_Unfreeze(); - - if (!(Pipe_BytesInPipe())) - return PIPE_READYWAIT_NoError; - - bool BankFull = !(Pipe_IsReadWriteAllowed()); - - Pipe_ClearOUT(); - - if (BankFull) - { - if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) - return ErrorCode; - - Pipe_ClearOUT(); - } - - Pipe_Freeze(); - - return PIPE_READYWAIT_NoError; -} - -#if defined(FDEV_SETUP_STREAM) -void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - FILE* const Stream) -{ - *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar, _FDEV_SETUP_RW); - fdev_set_udata(Stream, AOAInterfaceInfo); -} - -void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - FILE* const Stream) -{ - *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar_Blocking, _FDEV_SETUP_RW); - fdev_set_udata(Stream, AOAInterfaceInfo); -} - -static int AOA_Host_putchar(char c, - FILE* Stream) -{ - return AOA_Host_SendByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0; -} - -static int AOA_Host_getchar(FILE* Stream) -{ - int16_t ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); - - if (ReceivedByte < 0) - return _FDEV_EOF; - - return ReceivedByte; -} - -static int AOA_Host_getchar_Blocking(FILE* Stream) -{ - int16_t ReceivedByte; - - while ((ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream))) < 0) - { - if (USB_HostState == HOST_STATE_Unattached) - return _FDEV_EOF; - - AOA_Host_USBTask((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); - USB_USBTask(); - } - - return ReceivedByte; -} -#endif - -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#define __INCLUDE_FROM_USB_DRIVER +#include "../../Core/USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#define __INCLUDE_FROM_AOA_DRIVER +#define __INCLUDE_FROM_ANDROIDACCESSORY_HOST_C +#include "AndroidAccessoryClassHost.h" + +bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const USB_Descriptor_Device_t* const DeviceDescriptor, + bool* const NeedModeSwitch) +{ + (void)AOAInterfaceInfo; + + if (DeviceDescriptor->Header.Type != DTYPE_Device) + return false; + + *NeedModeSwitch = ((DeviceDescriptor->ProductID != ANDROID_ACCESSORY_PRODUCT_ID) && + (DeviceDescriptor->ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID)); + + return true; +} + +uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + uint16_t ConfigDescriptorSize, + void* ConfigDescriptorData) +{ + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Interface_t* AOAInterface = NULL; + + memset(&AOAInterfaceInfo->State, 0x00, sizeof(AOAInterfaceInfo->State)); + + if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration) + return AOA_ENUMERROR_InvalidConfigDescriptor; + + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + DCOMP_AOA_Host_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + return AOA_ENUMERROR_NoCompatibleInterfaceFound; + } + + AOAInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t); + + while (!(DataINEndpoint) || !(DataOUTEndpoint)) + { + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + DCOMP_AOA_Host_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + { + return AOA_ENUMERROR_NoCompatibleInterfaceFound; + } + + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); + + if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN) + DataINEndpoint = EndpointData; + else + DataOUTEndpoint = EndpointData; + } + + AOAInterfaceInfo->Config.DataINPipe.Size = le16_to_cpu(DataINEndpoint->EndpointSize); + AOAInterfaceInfo->Config.DataINPipe.EndpointAddress = DataINEndpoint->EndpointAddress; + AOAInterfaceInfo->Config.DataINPipe.Type = EP_TYPE_BULK; + + AOAInterfaceInfo->Config.DataOUTPipe.Size = le16_to_cpu(DataOUTEndpoint->EndpointSize); + AOAInterfaceInfo->Config.DataOUTPipe.EndpointAddress = DataOUTEndpoint->EndpointAddress; + AOAInterfaceInfo->Config.DataOUTPipe.Type = EP_TYPE_BULK; + + if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataINPipe, 1))) + return false; + + if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataOUTPipe, 1))) + return false; + + AOAInterfaceInfo->State.IsActive = true; + AOAInterfaceInfo->State.InterfaceNumber = AOAInterface->InterfaceNumber; + + return AOA_ENUMERROR_NoError; +} + +static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor) +{ + USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); + + if (Header->Type == DTYPE_Interface) + { + USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t); + + if ((Interface->Class == AOA_CSCP_AOADataClass) && + (Interface->SubClass == AOA_CSCP_AOADataSubclass) && + (Interface->Protocol == AOA_CSCP_AOADataProtocol)) + { + return DESCRIPTOR_SEARCH_Found; + } + } + + return DESCRIPTOR_SEARCH_NotFound; +} + +static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) +{ + USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); + + if (Header->Type == DTYPE_Endpoint) + { + USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t); + + uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK); + + if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress)))) + return DESCRIPTOR_SEARCH_Found; + } + else if (Header->Type == DTYPE_Interface) + { + return DESCRIPTOR_SEARCH_Fail; + } + + return DESCRIPTOR_SEARCH_NotFound; +} + +void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return; + + #if !defined(NO_CLASS_DRIVER_AUTOFLUSH) + AOA_Host_Flush(AOAInterfaceInfo); + #endif +} + +uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + uint8_t ErrorCode; + + uint16_t AccessoryProtocol; + if ((ErrorCode = AOA_Host_GetAccessoryProtocol(&AccessoryProtocol)) != HOST_WAITERROR_Successful) + return ErrorCode; + + if (AccessoryProtocol != CPU_TO_LE16(AOA_PROTOCOL_AccessoryV1)) + return AOA_ERROR_LOGICAL_CMD_FAILED; + + for (uint8_t PropertyIndex = 0; PropertyIndex < AOA_STRING_TOTAL_STRINGS; PropertyIndex++) + { + if ((ErrorCode = AOA_Host_SendPropertyString(AOAInterfaceInfo, PropertyIndex)) != HOST_WAITERROR_Successful) + return ErrorCode; + } + + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE), + .bRequest = AOA_REQ_StartAccessoryMode, + .wValue = 0, + .wIndex = 0, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + return USB_Host_SendControlRequest(NULL); +} + +static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE), + .bRequest = AOA_REQ_GetAccessoryProtocol, + .wValue = 0, + .wIndex = 0, + .wLength = sizeof(uint16_t), + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + return USB_Host_SendControlRequest(Protocol); +} + +static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t StringIndex) +{ + const char* String = AOAInterfaceInfo->Config.PropertyStrings[StringIndex]; + + if (String == NULL) + String = ""; + + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE), + .bRequest = AOA_REQ_SendString, + .wValue = 0, + .wIndex = StringIndex, + .wLength = (strlen(String) + 1), + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + return USB_Host_SendControlRequest((char*)String); +} + +uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t* const Buffer, + const uint16_t Length) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return PIPE_READYWAIT_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); + + Pipe_Unfreeze(); + ErrorCode = Pipe_Write_Stream_LE(Buffer, Length, NULL); + Pipe_Freeze(); + + return ErrorCode; +} + +uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const char* const String) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return PIPE_READYWAIT_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); + + Pipe_Unfreeze(); + ErrorCode = Pipe_Write_Stream_LE(String, strlen(String), NULL); + Pipe_Freeze(); + + return ErrorCode; +} + +uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t Data) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return PIPE_READYWAIT_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); + Pipe_Unfreeze(); + + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearOUT(); + + if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) + return ErrorCode; + } + + Pipe_Write_8(Data); + Pipe_Freeze(); + + return PIPE_READYWAIT_NoError; +} + +uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return 0; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address); + Pipe_Unfreeze(); + + if (Pipe_IsINReceived()) + { + if (!(Pipe_BytesInPipe())) + { + Pipe_ClearIN(); + Pipe_Freeze(); + return 0; + } + else + { + Pipe_Freeze(); + return Pipe_BytesInPipe(); + } + } + else + { + Pipe_Freeze(); + + return 0; + } +} + +int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return -1; + + int16_t ReceivedByte = -1; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address); + Pipe_Unfreeze(); + + if (Pipe_IsINReceived()) + { + if (Pipe_BytesInPipe()) + ReceivedByte = Pipe_Read_8(); + + if (!(Pipe_BytesInPipe())) + Pipe_ClearIN(); + } + + Pipe_Freeze(); + + return ReceivedByte; +} + +uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) +{ + if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive)) + return PIPE_READYWAIT_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address); + Pipe_Unfreeze(); + + if (!(Pipe_BytesInPipe())) + return PIPE_READYWAIT_NoError; + + bool BankFull = !(Pipe_IsReadWriteAllowed()); + + Pipe_ClearOUT(); + + if (BankFull) + { + if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) + return ErrorCode; + + Pipe_ClearOUT(); + } + + Pipe_Freeze(); + + return PIPE_READYWAIT_NoError; +} + +#if defined(FDEV_SETUP_STREAM) +void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + FILE* const Stream) +{ + *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar, _FDEV_SETUP_RW); + fdev_set_udata(Stream, AOAInterfaceInfo); +} + +void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + FILE* const Stream) +{ + *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar_Blocking, _FDEV_SETUP_RW); + fdev_set_udata(Stream, AOAInterfaceInfo); +} + +static int AOA_Host_putchar(char c, + FILE* Stream) +{ + return AOA_Host_SendByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0; +} + +static int AOA_Host_getchar(FILE* Stream) +{ + int16_t ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); + + if (ReceivedByte < 0) + return _FDEV_EOF; + + return ReceivedByte; +} + +static int AOA_Host_getchar_Blocking(FILE* Stream) +{ + int16_t ReceivedByte; + + while ((ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream))) < 0) + { + if (USB_HostState == HOST_STATE_Unattached) + return _FDEV_EOF; + + AOA_Host_USBTask((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); + USB_USBTask(); + } + + return ReceivedByte; +} +#endif + +#endif + diff --git a/trunk/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.h b/trunk/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.h index f55cd340a..c437a4b61 100644 --- a/trunk/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.h +++ b/trunk/LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.h @@ -1,314 +1,314 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Host mode driver for the library USB Android Open Accessory Class driver. - * - * Host mode driver for the library USB Android Open Accessory Class driver. - * - * \note This file should not be included directly. It is automatically included as needed by the USB module driver - * dispatch header located in LUFA/Drivers/USB.h. - */ - -/** \ingroup Group_USBClassAOA - * \defgroup Group_USBClassAndroidAccessoryHost Android Open Accessory Class Host Mode Driver - * - * \section Sec_Dependencies Module Source Dependencies - * The following files must be built with any user project that uses this module: - * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) - * - * \section Sec_ModDescription Module Description - * Host Mode USB Class driver framework interface, for the Android Open Accessory USB Class driver. - * - * @{ - */ - -#ifndef __AOA_CLASS_HOST_H__ -#define __AOA_CLASS_HOST_H__ - - /* Includes: */ - #include "../../USB.h" - #include "../Common/AndroidAccessoryClassCommon.h" - - #include - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_AOA_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Error code for some Android Open Accessory Host functions, indicating a logical (and not hardware) error. */ - #define AOA_ERROR_LOGICAL_CMD_FAILED 0x80 - - /* Type Defines: */ - /** \brief Android Open Accessory Class Host Mode Configuration and State Structure. - * - * Class state structure. An instance of this structure should be made within the user application, - * and passed to each of the Android Open Accessory class driver functions as the \c AOAInterfaceInfo - * parameter. This stores each Android Open Accessory interface's configuration and state information. - */ - typedef struct - { - struct - { - USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */ - USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */ - - char* PropertyStrings[AOA_STRING_TOTAL_STRINGS]; /**< Android Accessory property strings, sent to identify the accessory when the - * Android device is switched into Open Accessory mode. */ - } Config; /**< Config data for the USB class interface within the device. All elements in this section - * must be set or the interface will fail to enumerate and operate correctly. - */ - struct - { - bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid - * after \ref AOA_Host_ConfigurePipes() is called and the Host state machine is in the - * Configured state. - */ - uint8_t InterfaceNumber; /**< Interface index of the AOA interface within the attached device. */ - } State; /**< State data for the USB class interface within the device. All elements in this section - * may be set to initial values, but may also be ignored to default to sane values when - * the interface is enumerated. - */ - } USB_ClassInfo_AOA_Host_t; - - /* Enums: */ - /** Enum for the possible error codes returned by the \ref AOA_Host_ConfigurePipes() function. */ - enum AOA_Host_EnumerationFailure_ErrorCodes_t - { - AOA_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */ - AOA_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */ - AOA_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible Android Open Accessory interface was not found in the device's Configuration Descriptor. */ - AOA_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */ - }; - - /* Function Prototypes: */ - /** General management task for a given Android Open Accessory host class interface, required for the correct operation of the interface. - * This should be called frequently in the main program loop, before the master USB management task \ref USB_USBTask(). - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an Android Open Accessory Class host configuration and state. - */ - void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Validates a device descriptor, to check if the device is a valid Android device, and if it is currently in Android Open Accessory mode. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. - * \param[in] DeviceDescriptor Pointer a buffer containing the attached device's Device Descriptor. - * \param[out] NeedModeSwitch Pointer to a boolean where the mode switch requirement of the attached device is to be stored. - * - * \return Boolean \c true if the attached device is a valid Android device, \c false otherwise. - */ - bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const USB_Descriptor_Device_t* const DeviceDescriptor, - bool* const NeedModeSwitch) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3); - - /** Host interface configuration routine, to configure a given Android Open Accessory host interface instance using the Configuration - * Descriptor read from an attached USB device. This function automatically updates the given Android Open Accessory Host instance's - * state values and configures the pipes required to communicate with the interface if it is found within the device. This should be - * called once after the stack has enumerated the attached device, while the host state machine is in the Addressed state. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. - * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor. - * \param[in] ConfigDescriptorData Pointer to a buffer containing the attached device's Configuration Descriptor. - * - * \return A value from the \ref AOA_Host_EnumerationFailure_ErrorCodes_t enum. - */ - uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - uint16_t ConfigDescriptorSize, - void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3); - - /** Starts Accessory Mode in the attached Android device. This function will validate the device's Android Open Accessory protocol - * version, send the configured property strings, and request a switch to Android Open Accessory mode. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. - * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum, or \ref AOA_ERROR_LOGICAL_CMD_FAILED if a logical error occurred.. - */ - uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Sends a given data buffer to the attached USB device, if connected. If a device is not connected when the function is - * called, the data will be discarded. Bytes will be queued for transmission to the device until either the pipe bank - * becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows for - * multiple bytes to be packed into a single pipe packet, increasing data throughput. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * \param[in] Buffer Pointer to a buffer containing the data to send to the device. - * \param[in] Length Length of the data to send to the device. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t* const Buffer, - const uint16_t Length); - - /** Sends a given null-terminated string to the attached USB device, if connected. If a device is not connected when the - * function is called, the string is discarded. Bytes will be queued for transmission to the device until either the pipe - * bank becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows - * for multiple bytes to be packed into a single pipe packet, increasing data throughput. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * \param[in] String Pointer to the null terminated string to send to the device. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const char* const String) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2); - - /** Sends a given byte to the attached USB device, if connected. If a device is not connected when the function is called, the - * byte is discarded. Bytes will be queued for transmission to the device until either the pipe bank becomes full, or the - * \ref AOA_Host_Flush() function is called to flush the pending data to the host. This allows for multiple bytes to be - * packed into a single pipe packet, increasing data throughput. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * \param[in] Data Byte of data to send to the device. - * - * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. - */ - uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1); - - /** Determines the number of bytes received by the AOA interface from the device, waiting to be read. This indicates the number - * of bytes in the IN pipe bank only, and thus the number of calls to \ref AOA_Host_ReceiveByte() which are guaranteed to succeed - * immediately. If multiple bytes are to be received, they should be buffered by the user application, as the pipe bank will not be - * released back to the USB controller until all bytes are read. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * - * \return Total number of buffered bytes received from the device. - */ - uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Reads a byte of data from the device. If no data is waiting to be read of if a USB device is not connected, the function - * returns a negative value. The \ref AOA_Host_BytesReceived() function may be queried in advance to determine how many bytes - * are currently buffered in the AOA interface's data receive pipe. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * - * \return Next received byte from the device, or a negative value if no data received. - */ - int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Flushes any data waiting to be sent, ensuring that the send buffer is cleared. - * - * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the - * call will fail. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. - * - * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. - */ - uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); - - /** Creates a standard character stream for the given AOA Device instance so that it can be used with all the regular - * functions in the standard \c library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created - * stream is bidirectional and can be used for both input and output functions. - * - * Reading data from this stream is non-blocking, i.e. in most instances, complete strings cannot be read in by a single - * fetch, as the endpoint will not be ready at some point in the transmission, aborting the transfer. However, this may - * be used when the read data is processed byte-per-bye (via \c getc()) or when the user application will implement its own - * line buffering. - * - * \note The created stream can be given as \c stdout if desired to direct the standard output from all \c functions - * to the given AOA interface. - * \n\n - * - * \note This function is not available on all microcontroller architectures. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state. - * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. - */ - void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - FILE* const Stream); - - /** Identical to \ref AOA_Host_CreateStream(), except that reads are blocking until the calling stream function terminates - * the transfer. While blocking, the USB and AOA service tasks are called repeatedly to maintain USB communications. - * - * \note This function is not available on all microcontroller architectures. - * - * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state. - * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. - */ - void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - FILE* const Stream); - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - /* Function Prototypes: */ - #if defined(__INCLUDE_FROM_ANDROIDACCESSORY_HOST_C) - #if defined(FDEV_SETUP_STREAM) - static int AOA_Host_putchar(char c, - FILE* Stream) ATTR_NON_NULL_PTR_ARG(2); - static int AOA_Host_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); - static int AOA_Host_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); - #endif - - static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) ATTR_NON_NULL_PTR_ARG(1); - static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, - const uint8_t StringIndex) ATTR_NON_NULL_PTR_ARG(1); - - static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor) - ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1); - static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) - ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1); - #endif - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ - - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Host mode driver for the library USB Android Open Accessory Class driver. + * + * Host mode driver for the library USB Android Open Accessory Class driver. + * + * \note This file should not be included directly. It is automatically included as needed by the USB module driver + * dispatch header located in LUFA/Drivers/USB.h. + */ + +/** \ingroup Group_USBClassAOA + * \defgroup Group_USBClassAndroidAccessoryHost Android Open Accessory Class Host Mode Driver + * + * \section Sec_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) + * + * \section Sec_ModDescription Module Description + * Host Mode USB Class driver framework interface, for the Android Open Accessory USB Class driver. + * + * @{ + */ + +#ifndef __AOA_CLASS_HOST_H__ +#define __AOA_CLASS_HOST_H__ + + /* Includes: */ + #include "../../USB.h" + #include "../Common/AndroidAccessoryClassCommon.h" + + #include + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_AOA_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Error code for some Android Open Accessory Host functions, indicating a logical (and not hardware) error. */ + #define AOA_ERROR_LOGICAL_CMD_FAILED 0x80 + + /* Type Defines: */ + /** \brief Android Open Accessory Class Host Mode Configuration and State Structure. + * + * Class state structure. An instance of this structure should be made within the user application, + * and passed to each of the Android Open Accessory class driver functions as the \c AOAInterfaceInfo + * parameter. This stores each Android Open Accessory interface's configuration and state information. + */ + typedef struct + { + struct + { + USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */ + USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */ + + char* PropertyStrings[AOA_STRING_TOTAL_STRINGS]; /**< Android Accessory property strings, sent to identify the accessory when the + * Android device is switched into Open Accessory mode. */ + } Config; /**< Config data for the USB class interface within the device. All elements in this section + * must be set or the interface will fail to enumerate and operate correctly. + */ + struct + { + bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid + * after \ref AOA_Host_ConfigurePipes() is called and the Host state machine is in the + * Configured state. + */ + uint8_t InterfaceNumber; /**< Interface index of the AOA interface within the attached device. */ + } State; /**< State data for the USB class interface within the device. All elements in this section + * may be set to initial values, but may also be ignored to default to sane values when + * the interface is enumerated. + */ + } USB_ClassInfo_AOA_Host_t; + + /* Enums: */ + /** Enum for the possible error codes returned by the \ref AOA_Host_ConfigurePipes() function. */ + enum AOA_Host_EnumerationFailure_ErrorCodes_t + { + AOA_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */ + AOA_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */ + AOA_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible Android Open Accessory interface was not found in the device's Configuration Descriptor. */ + AOA_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */ + }; + + /* Function Prototypes: */ + /** General management task for a given Android Open Accessory host class interface, required for the correct operation of the interface. + * This should be called frequently in the main program loop, before the master USB management task \ref USB_USBTask(). + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an Android Open Accessory Class host configuration and state. + */ + void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Validates a device descriptor, to check if the device is a valid Android device, and if it is currently in Android Open Accessory mode. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. + * \param[in] DeviceDescriptor Pointer a buffer containing the attached device's Device Descriptor. + * \param[out] NeedModeSwitch Pointer to a boolean where the mode switch requirement of the attached device is to be stored. + * + * \return Boolean \c true if the attached device is a valid Android device, \c false otherwise. + */ + bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const USB_Descriptor_Device_t* const DeviceDescriptor, + bool* const NeedModeSwitch) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3); + + /** Host interface configuration routine, to configure a given Android Open Accessory host interface instance using the Configuration + * Descriptor read from an attached USB device. This function automatically updates the given Android Open Accessory Host instance's + * state values and configures the pipes required to communicate with the interface if it is found within the device. This should be + * called once after the stack has enumerated the attached device, while the host state machine is in the Addressed state. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. + * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor. + * \param[in] ConfigDescriptorData Pointer to a buffer containing the attached device's Configuration Descriptor. + * + * \return A value from the \ref AOA_Host_EnumerationFailure_ErrorCodes_t enum. + */ + uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + uint16_t ConfigDescriptorSize, + void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3); + + /** Starts Accessory Mode in the attached Android device. This function will validate the device's Android Open Accessory protocol + * version, send the configured property strings, and request a switch to Android Open Accessory mode. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state. + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum, or \ref AOA_ERROR_LOGICAL_CMD_FAILED if a logical error occurred.. + */ + uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Sends a given data buffer to the attached USB device, if connected. If a device is not connected when the function is + * called, the data will be discarded. Bytes will be queued for transmission to the device until either the pipe bank + * becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows for + * multiple bytes to be packed into a single pipe packet, increasing data throughput. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * \param[in] Buffer Pointer to a buffer containing the data to send to the device. + * \param[in] Length Length of the data to send to the device. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t* const Buffer, + const uint16_t Length); + + /** Sends a given null-terminated string to the attached USB device, if connected. If a device is not connected when the + * function is called, the string is discarded. Bytes will be queued for transmission to the device until either the pipe + * bank becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows + * for multiple bytes to be packed into a single pipe packet, increasing data throughput. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * \param[in] String Pointer to the null terminated string to send to the device. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const char* const String) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2); + + /** Sends a given byte to the attached USB device, if connected. If a device is not connected when the function is called, the + * byte is discarded. Bytes will be queued for transmission to the device until either the pipe bank becomes full, or the + * \ref AOA_Host_Flush() function is called to flush the pending data to the host. This allows for multiple bytes to be + * packed into a single pipe packet, increasing data throughput. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * \param[in] Data Byte of data to send to the device. + * + * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. + */ + uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1); + + /** Determines the number of bytes received by the AOA interface from the device, waiting to be read. This indicates the number + * of bytes in the IN pipe bank only, and thus the number of calls to \ref AOA_Host_ReceiveByte() which are guaranteed to succeed + * immediately. If multiple bytes are to be received, they should be buffered by the user application, as the pipe bank will not be + * released back to the USB controller until all bytes are read. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * + * \return Total number of buffered bytes received from the device. + */ + uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads a byte of data from the device. If no data is waiting to be read of if a USB device is not connected, the function + * returns a negative value. The \ref AOA_Host_BytesReceived() function may be queried in advance to determine how many bytes + * are currently buffered in the AOA interface's data receive pipe. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * + * \return Next received byte from the device, or a negative value if no data received. + */ + int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Flushes any data waiting to be sent, ensuring that the send buffer is cleared. + * + * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the + * call will fail. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state. + * + * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. + */ + uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + + /** Creates a standard character stream for the given AOA Device instance so that it can be used with all the regular + * functions in the standard \c library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created + * stream is bidirectional and can be used for both input and output functions. + * + * Reading data from this stream is non-blocking, i.e. in most instances, complete strings cannot be read in by a single + * fetch, as the endpoint will not be ready at some point in the transmission, aborting the transfer. However, this may + * be used when the read data is processed byte-per-bye (via \c getc()) or when the user application will implement its own + * line buffering. + * + * \note The created stream can be given as \c stdout if desired to direct the standard output from all \c functions + * to the given AOA interface. + * \n\n + * + * \note This function is not available on all microcontroller architectures. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state. + * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. + */ + void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + FILE* const Stream); + + /** Identical to \ref AOA_Host_CreateStream(), except that reads are blocking until the calling stream function terminates + * the transfer. While blocking, the USB and AOA service tasks are called repeatedly to maintain USB communications. + * + * \note This function is not available on all microcontroller architectures. + * + * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state. + * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. + */ + void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + FILE* const Stream); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Function Prototypes: */ + #if defined(__INCLUDE_FROM_ANDROIDACCESSORY_HOST_C) + #if defined(FDEV_SETUP_STREAM) + static int AOA_Host_putchar(char c, + FILE* Stream) ATTR_NON_NULL_PTR_ARG(2); + static int AOA_Host_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); + static int AOA_Host_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); + #endif + + static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) ATTR_NON_NULL_PTR_ARG(1); + static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo, + const uint8_t StringIndex) ATTR_NON_NULL_PTR_ARG(1); + + static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1); + static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1); + #endif + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + + diff --git a/trunk/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c b/trunk/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c index 0117a1d66..a267be1ee 100644 --- a/trunk/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c +++ b/trunk/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c @@ -1,275 +1,275 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#include "../../../../Common/Common.h" -#if (ARCH == ARCH_AVR8) - -#define __INCLUDE_FROM_USB_DRIVER -#include "../USBMode.h" - -#if defined(USB_CAN_BE_DEVICE) - -#include "EndpointStream_AVR8.h" - -#if !defined(CONTROL_ONLY_DEVICE) -uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Discard_8(); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Write_8(0); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, - * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" -#endif - -#endif - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_Control_R.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_Control_R.c" -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVR8) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "EndpointStream_AVR8.h" + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Discard_8(); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Write_8(0); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, + * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" #endif -#endif +#endif + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_Control_R.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_Control_R.c" +#endif + +#endif + +#endif diff --git a/trunk/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h b/trunk/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h index 072d85932..2d98ef4d6 100644 --- a/trunk/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h +++ b/trunk/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h @@ -1,648 +1,648 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Endpoint data stream transmission and reception management for the AVR8 microcontrollers. - * \copydetails Group_EndpointStreamRW_AVR8 - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_EndpointStreamRW - * \defgroup Group_EndpointStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8) - * \brief Endpoint data stream transmission and reception management for the Atmel AVR8 architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to endpoints. - * - * @{ - */ - -#ifndef __ENDPOINT_STREAM_AVR8_H__ -#define __ENDPOINT_STREAM_AVR8_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** Reads and discards the given number of bytes from the currently selected endpoint's bank, - * 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of bytes to discard via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending - * full packets to the host as needed. The last packet is not automatically sent once the - * remaining bytes have been written; the user is responsible for manually sending the last - * packet to the host via the \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of zero bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Endpoint_ClearIN() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for EEPROM source/destination data */ - //@{ - - /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_EStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_EStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE(). - * - * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_EStream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE(). - * - * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_EStream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for PROGMEM source/destination data */ - //@{ - - /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_PStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_PStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Endpoint data stream transmission and reception management for the AVR8 microcontrollers. + * \copydetails Group_EndpointStreamRW_AVR8 + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointStreamRW + * \defgroup Group_EndpointStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8) + * \brief Endpoint data stream transmission and reception management for the Atmel AVR8 architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + * + * @{ + */ + +#ifndef __ENDPOINT_STREAM_AVR8_H__ +#define __ENDPOINT_STREAM_AVR8_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** Reads and discards the given number of bytes from the currently selected endpoint's bank, + * 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of bytes to discard via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending + * full packets to the host as needed. The last packet is not automatically sent once the + * remaining bytes have been written; the user is responsible for manually sending the last + * packet to the host via the \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of zero bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Endpoint_ClearIN() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for EEPROM source/destination data */ + //@{ + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE(). + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE(). + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for PROGMEM source/destination data */ + //@{ + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/trunk/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h b/trunk/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h index 53316f2f9..f69469f28 100644 --- a/trunk/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h +++ b/trunk/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h @@ -1,442 +1,442 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Pipe data stream transmission and reception management for the AVR8 microcontrollers - * \copydetails Group_PipeStreamRW_AVR8 - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_PipeStreamRW - * \defgroup Group_PipeStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8) - * \brief Pipe data stream transmission and reception management for the Atmel AVR8 architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to pipes. - * - * @{ - */ - -#ifndef __PIPE_STREAM_AVR8_H__ -#define __PIPE_STREAM_AVR8_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** 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 device via the \ref Pipe_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or - * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer - * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data - * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with - * the total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to - * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed - * value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Length Number of bytes to discard via the currently selected pipe. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be processed at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device - * as needed. The last packet is not automatically sent once the remaining bytes has been written; the - * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or - * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer - * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data - * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be - * updated with the total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to - * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed - * value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Length Number of zero bytes to write via the currently selected pipe. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be processed at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Pipe_ClearOUT() 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. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the pipe bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Pipe_ClearOUT() 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. - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** 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 - * \ref Pipe_ClearIN() 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. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the pipe bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Pipe_ClearIN() 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. - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for EEPROM source/destination data */ - //@{ - - /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_EStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_EStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_EStream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_EStream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for PROGMEM source/destination data */ - //@{ - - /** FLASH buffer source version of \ref Pipe_Write_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_PStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Pipe_Write_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_PStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Pipe data stream transmission and reception management for the AVR8 microcontrollers + * \copydetails Group_PipeStreamRW_AVR8 + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_PipeStreamRW + * \defgroup Group_PipeStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8) + * \brief Pipe data stream transmission and reception management for the Atmel AVR8 architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to pipes. + * + * @{ + */ + +#ifndef __PIPE_STREAM_AVR8_H__ +#define __PIPE_STREAM_AVR8_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** 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 device via the \ref Pipe_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or + * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer + * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data + * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with + * the total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to + * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed + * value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Length Number of bytes to discard via the currently selected pipe. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be processed at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device + * as needed. The last packet is not automatically sent once the remaining bytes has been written; the + * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or + * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer + * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data + * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be + * updated with the total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to + * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed + * value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Length Number of zero bytes to write via the currently selected pipe. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be processed at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Pipe_ClearOUT() 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. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the pipe bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Pipe_ClearOUT() 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. + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** 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 + * \ref Pipe_ClearIN() 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. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the pipe bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Pipe_ClearIN() 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. + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for EEPROM source/destination data */ + //@{ + + /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_EStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_EStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_EStream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_EStream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for PROGMEM source/destination data */ + //@{ + + /** FLASH buffer source version of \ref Pipe_Write_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_PStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Pipe_Write_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_PStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/trunk/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.c b/trunk/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.c index b4e130e74..515461065 100644 --- a/trunk/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.c +++ b/trunk/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.c @@ -1,235 +1,235 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#include "../../../../Common/Common.h" -#if (ARCH == ARCH_UC3) - -#define __INCLUDE_FROM_USB_DRIVER -#include "../USBMode.h" - -#if defined(USB_CAN_BE_DEVICE) - -#include "EndpointStream_UC3.h" - -#if !defined(CONTROL_ONLY_DEVICE) -uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Discard_8(); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Write_8(0); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, - * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" -#endif - -#endif - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_UC3) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "EndpointStream_UC3.h" + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Discard_8(); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Write_8(0); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, + * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" #endif -#endif +#endif + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#endif + +#endif diff --git a/trunk/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.h b/trunk/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.h index 40a54ee17..3eccb7f15 100644 --- a/trunk/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.h +++ b/trunk/LUFA/Drivers/USB/Core/UC3/EndpointStream_UC3.h @@ -1,434 +1,434 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Endpoint data stream transmission and reception management for the AVR32 UC3 microcontrollers. - * \copydetails Group_EndpointStreamRW_UC3 - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_EndpointStreamRW - * \defgroup Group_EndpointStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3) - * \brief Endpoint data stream transmission and reception management for the Atmel AVR32 UC3 architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to endpoints. - * - * @{ - */ - -#ifndef __ENDPOINT_STREAM_UC3_H__ -#define __ENDPOINT_STREAM_UC3_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** Reads and discards the given number of bytes from the currently selected endpoint's bank, - * 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of bytes to discard via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending - * full packets to the host as needed. The last packet is not automatically sent once the - * remaining bytes have been written; the user is responsible for manually sending the last - * packet to the host via the \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of zero bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Endpoint_ClearIN() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Endpoint data stream transmission and reception management for the AVR32 UC3 microcontrollers. + * \copydetails Group_EndpointStreamRW_UC3 + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointStreamRW + * \defgroup Group_EndpointStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3) + * \brief Endpoint data stream transmission and reception management for the Atmel AVR32 UC3 architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + * + * @{ + */ + +#ifndef __ENDPOINT_STREAM_UC3_H__ +#define __ENDPOINT_STREAM_UC3_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** Reads and discards the given number of bytes from the currently selected endpoint's bank, + * 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of bytes to discard via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending + * full packets to the host as needed. The last packet is not automatically sent once the + * remaining bytes have been written; the user is responsible for manually sending the last + * packet to the host via the \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of zero bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Endpoint_ClearIN() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/trunk/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.c b/trunk/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.c index bb4cbc659..76fbfd8f5 100644 --- a/trunk/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.c +++ b/trunk/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.c @@ -1,166 +1,166 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#include "../../../../Common/Common.h" -#if (ARCH == ARCH_UC3) - -#define __INCLUDE_FROM_USB_DRIVER -#include "../USBMode.h" - -#if defined(USB_CAN_BE_HOST) - -#include "PipeStream_UC3.h" - -uint8_t Pipe_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - Pipe_SetPipeToken(PIPE_TOKEN_IN); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearIN(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return PIPE_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - else - { - Pipe_Discard_8(); - - Length--; - BytesInTransfer++; - } - } - - return PIPE_RWSTREAM_NoError; -} - -uint8_t Pipe_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - Pipe_SetPipeToken(PIPE_TOKEN_OUT); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearOUT(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return PIPE_RWSTREAM_IncompleteTransfer; - } - - USB_USBTask(); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - else - { - Pipe_Write_8(0); - - Length--; - BytesInTransfer++; - } - } - - return PIPE_RWSTREAM_NoError; -} - -/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, - * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ - -#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_TOKEN PIPE_TOKEN_OUT -#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr) -#include "Template/Template_Pipe_RW.c" - -#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_TOKEN PIPE_TOKEN_OUT -#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr) -#include "Template/Template_Pipe_RW.c" - -#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_TOKEN PIPE_TOKEN_IN -#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8() -#include "Template/Template_Pipe_RW.c" - -#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_TOKEN PIPE_TOKEN_IN -#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8() -#include "Template/Template_Pipe_RW.c" - -#endif - -#endif +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_UC3) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#include "PipeStream_UC3.h" + +uint8_t Pipe_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + Pipe_SetPipeToken(PIPE_TOKEN_IN); + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return PIPE_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + else + { + Pipe_Discard_8(); + + Length--; + BytesInTransfer++; + } + } + + return PIPE_RWSTREAM_NoError; +} + +uint8_t Pipe_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + Pipe_SetPipeToken(PIPE_TOKEN_OUT); + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return PIPE_RWSTREAM_IncompleteTransfer; + } + + USB_USBTask(); + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + else + { + Pipe_Write_8(0); + + Length--; + BytesInTransfer++; + } + } + + return PIPE_RWSTREAM_NoError; +} + +/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, + * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ + +#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_TOKEN PIPE_TOKEN_OUT +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_TOKEN PIPE_TOKEN_OUT +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_TOKEN PIPE_TOKEN_IN +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8() +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_TOKEN PIPE_TOKEN_IN +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8() +#include "Template/Template_Pipe_RW.c" + +#endif + +#endif diff --git a/trunk/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.h b/trunk/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.h index cb8a28c86..72bf83c6c 100644 --- a/trunk/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.h +++ b/trunk/LUFA/Drivers/USB/Core/UC3/PipeStream_UC3.h @@ -1,352 +1,352 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Pipe data stream transmission and reception management for the AVR32 UC3 microcontrollers. - * \copydetails Group_PipeStreamRW_UC3 - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_PipeStreamRW - * \defgroup Group_PipeStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3) - * \brief Pipe data stream transmission and reception management for the Atmel AVR32 UC3 architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to pipes. - * - * @{ - */ - -#ifndef __PIPE_STREAM_UC3_H__ -#define __PIPE_STREAM_UC3_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** 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 device via the \ref Pipe_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or - * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer - * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data - * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with - * the total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to - * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed - * value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Length Number of bytes to discard via the currently selected pipe. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be processed at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device - * as needed. The last packet is not automatically sent once the remaining bytes has been written; the - * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or - * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer - * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data - * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be - * updated with the total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to - * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed - * value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Length Number of zero bytes to write via the currently selected pipe. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be processed at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Pipe_ClearOUT() 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. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the pipe bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Pipe_ClearOUT() 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. - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** 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 - * \ref Pipe_ClearIN() 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. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the pipe bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != PIPE_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Pipe_ClearIN() 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. - * - * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). - * - * \param[out] Buffer Pointer to the source data buffer to write to. - * \param[in] Length Number of bytes to read for the currently selected pipe to read from. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should - * updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Pipe_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Pipe data stream transmission and reception management for the AVR32 UC3 microcontrollers. + * \copydetails Group_PipeStreamRW_UC3 + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_PipeStreamRW + * \defgroup Group_PipeStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3) + * \brief Pipe data stream transmission and reception management for the Atmel AVR32 UC3 architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to pipes. + * + * @{ + */ + +#ifndef __PIPE_STREAM_UC3_H__ +#define __PIPE_STREAM_UC3_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** 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 device via the \ref Pipe_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or + * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer + * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data + * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with + * the total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to + * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed + * value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Length Number of bytes to discard via the currently selected pipe. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be processed at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device + * as needed. The last packet is not automatically sent once the remaining bytes has been written; the + * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or + * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer + * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data + * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be + * updated with the total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to + * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed + * value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Length Number of zero bytes to write via the currently selected pipe. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be processed at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Pipe_ClearOUT() 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. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the pipe bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Pipe_ClearOUT() 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. + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** 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 + * \ref Pipe_ClearIN() 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. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the pipe bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != PIPE_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Pipe_ClearIN() 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. + * + * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should + * updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/trunk/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.c b/trunk/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.c index 774a574f3..db804506e 100644 --- a/trunk/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.c +++ b/trunk/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.c @@ -1,275 +1,275 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) - -#define __INCLUDE_FROM_USB_DRIVER -#include "../USBMode.h" - -#if defined(USB_CAN_BE_DEVICE) - -#include "EndpointStream_XMEGA.h" - -#if !defined(CONTROL_ONLY_DEVICE) -uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Discard_8(); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed) -{ - uint8_t ErrorCode; - uint16_t BytesInTransfer = 0; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - if (BytesProcessed != NULL) - Length -= *BytesProcessed; - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - if (BytesProcessed != NULL) - { - *BytesProcessed += BytesInTransfer; - return ENDPOINT_RWSTREAM_IncompleteTransfer; - } - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Write_8(0); - - Length--; - BytesInTransfer++; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, - * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE -#define TEMPLATE_BUFFER_TYPE const void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE -#define TEMPLATE_BUFFER_TYPE void* -#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_RW.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE - #define TEMPLATE_BUFFER_TYPE const void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE - #define TEMPLATE_BUFFER_TYPE void* - #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_RW.c" -#endif - -#endif - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) -#include "Template/Template_Endpoint_Control_W.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE -#define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE -#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() -#include "Template/Template_Endpoint_Control_R.c" - -#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" -#endif - -#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) - #include "Template/Template_Endpoint_Control_W.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE - #define TEMPLATE_BUFFER_OFFSET(Length) 0 - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_Control_R.c" - - #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE - #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) - #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount - #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) - #include "Template/Template_Endpoint_Control_R.c" -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_XMEGA) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "EndpointStream_XMEGA.h" + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Discard_8(); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + Endpoint_Write_8(0); + + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations, + * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */ + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE +#define TEMPLATE_BUFFER_TYPE const void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE +#define TEMPLATE_BUFFER_TYPE void* +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_RW.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE + #define TEMPLATE_BUFFER_TYPE const void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE + #define TEMPLATE_BUFFER_TYPE void* + #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_RW.c" #endif -#endif +#endif + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8() +#include "Template/Template_Endpoint_Control_R.c" + +#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" +#endif + +#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr)) + #include "Template/Template_Endpoint_Control_W.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE + #define TEMPLATE_BUFFER_OFFSET(Length) 0 + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_Control_R.c" + + #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE + #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) + #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount + #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8()) + #include "Template/Template_Endpoint_Control_R.c" +#endif + +#endif + +#endif diff --git a/trunk/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.h b/trunk/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.h index 3269d2b1d..436752880 100644 --- a/trunk/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.h +++ b/trunk/LUFA/Drivers/USB/Core/XMEGA/EndpointStream_XMEGA.h @@ -1,648 +1,648 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Endpoint data stream transmission and reception management for the AVR XMEGA microcontrollers. - * \copydetails Group_EndpointStreamRW_XMEGA - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_EndpointStreamRW - * \defgroup Group_EndpointStreamRW_XMEGA Read/Write of Multi-Byte Streams (XMEGA) - * \brief Endpoint data stream transmission and reception management for the Atmel AVR XMEGA architecture. - * - * Functions, macros, variables, enums and types related to data reading and writing of data streams from - * and to endpoints. - * - * @{ - */ - -#ifndef __ENDPOINT_STREAM_XMEGA_H__ -#define __ENDPOINT_STREAM_XMEGA_H__ - - /* Includes: */ - #include "../../../../Common/Common.h" - #include "../USBMode.h" - #include "../USBTask.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Function Prototypes: */ - /** \name Stream functions for null data */ - //@{ - - /** Reads and discards the given number of bytes from the currently selected endpoint's bank, - * 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of bytes to discard via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Discard_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending - * full packets to the host as needed. The last packet is not automatically sent once the - * remaining bytes have been written; the user is responsible for manually sending the last - * packet to the host via the \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Length Number of zero bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Null_Stream(uint16_t Length, - uint16_t* const BytesProcessed); - - //@} - - /** \name Stream functions for RAM source/destination data */ - //@{ - - /** 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 - * \ref Endpoint_ClearIN() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes full while there is still data to process (and after the current - * packet transmission has been initiated) the BytesProcessed location will be updated with the - * total number of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 - * \ref Endpoint_ClearIN() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, - * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid - * storage location, the transfer will instead be performed as a series of chunks. Each time - * the endpoint bank becomes empty while there is still data to process (and after the current - * packet has been acknowledged) the BytesProcessed location will be updated with the total number - * of bytes processed in the stream, and the function will exit with an error code of - * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed - * in the user code - to continue the transfer, call the function again with identical parameters - * and it will resume until the BytesProcessed value reaches the total transfer length. - * - * Single Stream Transfer Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * - * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * NULL)) != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * Partial Stream Transfers Example: - * \code - * uint8_t DataStream[512]; - * uint8_t ErrorCode; - * uint16_t BytesProcessed; - * - * BytesProcessed = 0; - * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), - * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) - * { - * // Stream not yet complete - do other actions here, abort if required - * } - * - * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) - * { - * // Stream failed to complete - check ErrorCode here - * } - * \endcode - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. - * - * \note This routine should not be used on CONTROL type endpoints. - * - * \param[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Stream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for EEPROM source/destination data */ - //@{ - - /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_EStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE(). - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_EStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE(). - * - * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_EStream_LE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE(). - * - * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be read at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_EStream_BE(void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE(). - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[out] Buffer Pointer to the destination data buffer to write to. - * \param[in] Length Number of bytes to send via the currently selected endpoint. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /** \name Stream functions for PROGMEM source/destination data */ - //@{ - - /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_PStream_LE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \param[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current - * transaction should be updated, \c NULL if the entire stream should be written at once. - * - * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_PStream_BE(const void* const Buffer, - uint16_t Length, - uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - - /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE(). - * - * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. - * - * \note This function automatically clears the control transfer's status stage. Do not manually attempt - * to clear the status stage when using this routine in a control transaction. - * \n\n - * - * \note This routine should only be used on CONTROL type endpoints. - * \n\n - * - * \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[in] Buffer Pointer to the source data buffer to read from. - * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. - * - * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. - */ - uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer, - uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); - //@} - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Endpoint data stream transmission and reception management for the AVR XMEGA microcontrollers. + * \copydetails Group_EndpointStreamRW_XMEGA + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointStreamRW + * \defgroup Group_EndpointStreamRW_XMEGA Read/Write of Multi-Byte Streams (XMEGA) + * \brief Endpoint data stream transmission and reception management for the Atmel AVR XMEGA architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + * + * @{ + */ + +#ifndef __ENDPOINT_STREAM_XMEGA_H__ +#define __ENDPOINT_STREAM_XMEGA_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + //@{ + + /** Reads and discards the given number of bytes from the currently selected endpoint's bank, + * 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of bytes to discard via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending + * full packets to the host as needed. The last packet is not automatically sent once the + * remaining bytes have been written; the user is responsible for manually sending the last + * packet to the host via the \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of zero bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + //@} + + /** \name Stream functions for RAM source/destination data */ + //@{ + + /** 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 + * \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 + * \ref Endpoint_ClearIN() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 \ref Endpoint_ClearOUT() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_LE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_Stream_BE(const void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_LE(void* const 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 acknowledgement 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 \ref Endpoint_ClearIN() macro. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for EEPROM source/destination data */ + //@{ + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE(). + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE(). + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE(). + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE(). + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /** \name Stream functions for PROGMEM source/destination data */ + //@{ + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE(). + * + * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This function automatically clears the control transfer's status stage. Do not manually attempt + * to clear the status stage when using this routine in a control transaction. + * \n\n + * + * \note This routine should only be used on CONTROL type endpoints. + * \n\n + * + * \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[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + //@} + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/trunk/LUFA/Platform/UC3/ClockManagement.h b/trunk/LUFA/Platform/UC3/ClockManagement.h index 51cb0ff6d..ac2431476 100644 --- a/trunk/LUFA/Platform/UC3/ClockManagement.h +++ b/trunk/LUFA/Platform/UC3/ClockManagement.h @@ -231,6 +231,12 @@ const uint32_t SourceFreq, const uint32_t Frequency) { + if (Channel >= AVR32_PM_GCLK_NUM) + return false; + + if (SourceFreq < Frequency) + return false; + switch (Source) { case CLOCK_SRC_OSC0: @@ -253,9 +259,6 @@ return false; } - if (SourceFreq < Frequency) - return false; - AVR32_PM.GCCTRL[Channel].diven = (SourceFreq > Frequency) ? true : false; AVR32_PM.GCCTRL[Channel].div = (((SourceFreq / Frequency) - 1) / 2); AVR32_PM.GCCTRL[Channel].cen = true; @@ -266,11 +269,18 @@ /** Stops the given generic clock of the UC3 microcontroller. * * \param[in] Channel Index of the generic clock to stop. + * + * \return Boolean \c true if the generic clock was sucessfully stopped, \c false if invalid parameters specified. */ - static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE; - static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) + static inline bool AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE; + static inline bool AVR32CLK_StopGenericClock(const uint8_t Channel) { + if (Channel >= AVR32_PM_GCLK_NUM) + return false; + AVR32_PM.GCCTRL[Channel].cen = false; + + return true; } /** Sets the clock source for the main microcontroller core. The given clock source should be configured @@ -288,8 +298,11 @@ static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source, const uint32_t SourceFreq) { - AVR32_FLASHC.FCR.fws = (SourceFreq > 30000000) ? true : false; + if (SourceFreq > AVR32_PM_CPU_MAX_FREQ) + return false; + AVR32_FLASHC.FCR.fws = (SourceFreq > AVR32_FLASHC_FWS_0_MAX_FREQ) ? true : false; + switch (Source) { #if defined(AVR32_PM_MCCTRL_MCSEL_SLOW) diff --git a/trunk/LUFA/makefile b/trunk/LUFA/makefile index ebe2b19be..21f0f578a 100644 --- a/trunk/LUFA/makefile +++ b/trunk/LUFA/makefile @@ -45,3 +45,6 @@ else include Build/lufa.sources.in include Build/lufa.doxygen.in endif + + +.PHONY: all export_tar version clean \ No newline at end of file diff --git a/trunk/Maintenance/makefile b/trunk/Maintenance/makefile index 3f542721a..f15838178 100644 --- a/trunk/Maintenance/makefile +++ b/trunk/Maintenance/makefile @@ -89,3 +89,6 @@ validate-branch: # Validate the working branch for general release, check for placeholder documentation then build and test everything validate-release: check-documentation-placeholders validate-branch + + +.PHONY: all upgrade-doxygen make-as4-projects check-documentation-placeholders validate-branch \ No newline at end of file diff --git a/trunk/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c b/trunk/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c index b77c18058..6bf74c872 100644 --- a/trunk/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c +++ b/trunk/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c @@ -361,7 +361,7 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, } /* Program complete - reset timeout */ - wdt_reset(); + TimeoutTicksRemaining = COMMAND_TIMEOUT_TICKS; return ProgrammingStatus; } diff --git a/trunk/Projects/AVRISP-MKII/makefile b/trunk/Projects/AVRISP-MKII/makefile index 25cd17952..a24ced974 100644 --- a/trunk/Projects/AVRISP-MKII/makefile +++ b/trunk/Projects/AVRISP-MKII/makefile @@ -32,5 +32,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/Benito/makefile b/trunk/Projects/Benito/makefile index b7ec8a9ca..333f2f6a5 100644 --- a/trunk/Projects/Benito/makefile +++ b/trunk/Projects/Benito/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/HIDReportViewer/makefile b/trunk/Projects/HIDReportViewer/makefile index b56e72f6c..ecb4989c1 100644 --- a/trunk/Projects/HIDReportViewer/makefile +++ b/trunk/Projects/HIDReportViewer/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/LEDNotifier/makefile b/trunk/Projects/LEDNotifier/makefile index 1c8e0a744..fa5f9ff46 100644 --- a/trunk/Projects/LEDNotifier/makefile +++ b/trunk/Projects/LEDNotifier/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/MIDIToneGenerator/makefile b/trunk/Projects/MIDIToneGenerator/makefile index 157a651be..0166c62e0 100644 --- a/trunk/Projects/MIDIToneGenerator/makefile +++ b/trunk/Projects/MIDIToneGenerator/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/Magstripe/makefile b/trunk/Projects/Magstripe/makefile index 7e92c1596..94504a0fe 100644 --- a/trunk/Projects/Magstripe/makefile +++ b/trunk/Projects/Magstripe/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/MediaController/makefile b/trunk/Projects/MediaController/makefile index 774e47f26..a87c5574c 100644 --- a/trunk/Projects/MediaController/makefile +++ b/trunk/Projects/MediaController/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/MissileLauncher/makefile b/trunk/Projects/MissileLauncher/makefile index 7e9433c48..de4ec444b 100644 --- a/trunk/Projects/MissileLauncher/makefile +++ b/trunk/Projects/MissileLauncher/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/RelayBoard/makefile b/trunk/Projects/RelayBoard/makefile index 6e680a3dd..553810500 100644 --- a/trunk/Projects/RelayBoard/makefile +++ b/trunk/Projects/RelayBoard/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/SerialToLCD/makefile b/trunk/Projects/SerialToLCD/makefile index 2c74f5fbc..3b4d5aefe 100644 --- a/trunk/Projects/SerialToLCD/makefile +++ b/trunk/Projects/SerialToLCD/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/TempDataLogger/makefile b/trunk/Projects/TempDataLogger/makefile index f5d5bf19b..d851cee5b 100644 --- a/trunk/Projects/TempDataLogger/makefile +++ b/trunk/Projects/TempDataLogger/makefile @@ -32,5 +32,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/USBtoSerial/makefile b/trunk/Projects/USBtoSerial/makefile index 270e9b663..0c837d08b 100644 --- a/trunk/Projects/USBtoSerial/makefile +++ b/trunk/Projects/USBtoSerial/makefile @@ -31,5 +31,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/Webserver/makefile b/trunk/Projects/Webserver/makefile index d3765ce70..0ef40a526 100644 --- a/trunk/Projects/Webserver/makefile +++ b/trunk/Projects/Webserver/makefile @@ -34,5 +34,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/Projects/XPLAINBridge/makefile b/trunk/Projects/XPLAINBridge/makefile index 6d6c289c5..304649849 100644 --- a/trunk/Projects/XPLAINBridge/makefile +++ b/trunk/Projects/XPLAINBridge/makefile @@ -37,5 +37,6 @@ include $(LUFA_PATH)/Build/lufa.build.in include $(LUFA_PATH)/Build/lufa.cppcheck.in include $(LUFA_PATH)/Build/lufa.doxygen.in include $(LUFA_PATH)/Build/lufa.dfu.in +include $(LUFA_PATH)/Build/lufa.hid.in include $(LUFA_PATH)/Build/lufa.avrdude.in include $(LUFA_PATH)/Build/lufa.atprogram.in diff --git a/trunk/makefile b/trunk/makefile index d533f25ac..898353c0d 100644 --- a/trunk/makefile +++ b/trunk/makefile @@ -17,9 +17,9 @@ all: %: @echo Executing \"make $@\" on all LUFA library elements. @echo - $(MAKE) -C LUFA $@ -s - $(MAKE) -C Demos $@ -s - $(MAKE) -C Projects $@ -s - $(MAKE) -C Bootloaders $@ -s + $(MAKE) -C LUFA $@ + $(MAKE) -C Demos $@ + $(MAKE) -C Projects $@ + $(MAKE) -C Bootloaders $@ @echo @echo LUFA \"make $@\" operation complete.