diff --git a/BuildTests/BoardDriverTest/BoardDeviceMap.cfg b/BuildTests/BoardDriverTest/BoardDeviceMap.cfg index 2100ed27a..cc108a6d7 100644 --- a/BuildTests/BoardDriverTest/BoardDeviceMap.cfg +++ b/BuildTests/BoardDriverTest/BoardDeviceMap.cfg @@ -89,3 +89,6 @@ BOARD_EVK1101 = UC3 : uc3b0256 : BOARD_EVK1104 = UC3 : uc3a3256 : BOARD_UC3A3_XPLAINED = UC3 : uc3a3256 : # +# ----------------- AVRDX Boards ----------------- +BOARD_AVR64DU32_CNANO = AVRDX : avr64du32 : +# diff --git a/BuildTests/BoardDriverTest/makefile b/BuildTests/BoardDriverTest/makefile index 014554f16..7ba0a5eec 100644 --- a/BuildTests/BoardDriverTest/makefile +++ b/BuildTests/BoardDriverTest/makefile @@ -59,6 +59,7 @@ clean: $(MAKE) -f makefile.test clean BOARD=NONE ARCH=AVR8 MCU=at90usb1287 $(MAKE) -f makefile.test clean BOARD=NONE ARCH=XMEGA MCU=atxmega128a1u $(MAKE) -f makefile.test clean BOARD=NONE ARCH=UC3 MCU=uc3a0256 + $(MAKE) -f makefile.test clean BOARD=NONE ARCH=AVRDX MCU=avr64du32 %: diff --git a/BuildTests/ModuleTest/Modules.h b/BuildTests/ModuleTest/Modules.h index ff2b961ce..9d5d0a535 100644 --- a/BuildTests/ModuleTest/Modules.h +++ b/BuildTests/ModuleTest/Modules.h @@ -53,4 +53,9 @@ #include #include #include +#elif (ARCH == ARCH_AVRDX) + #include + #include + #include + #include #endif diff --git a/BuildTests/ModuleTest/makefile b/BuildTests/ModuleTest/makefile index 68241476c..eff5529d8 100644 --- a/BuildTests/ModuleTest/makefile +++ b/BuildTests/ModuleTest/makefile @@ -22,9 +22,10 @@ LUFA_PATH := ../../LUFA/ AVR8_FAMILIES := at90usb1287 at90usb1286 atmega16u4 atmega16u2 at90usb162 XMEGA_FAMILIES := atxmega128a1u atxmega128a3u atxmega256a3bu atxmega128a4u atxmega128b1 atxmega128b3 atxmega128c3 atxmega32c4 UC3_FAMILIES := uc3a0256 uc3a1256 uc3a3256 uc3a4256 uc3b0256 uc3b1256 +AVRDX_FAMILIES := avr64du28 avr64du32 # List of all device families, with a family postfix -DEVICE_FAMILIES := $(AVR8_FAMILIES:%=%.avr8) $(XMEGA_FAMILIES:%=%.xmega) $(UC3_FAMILIES:%=%.uc3) +DEVICE_FAMILIES := $(AVR8_FAMILIES:%=%.avr8) $(XMEGA_FAMILIES:%=%.xmega) $(UC3_FAMILIES:%=%.uc3) $(AVRDX_FAMILIES:%=%.avrdx) all: begin $(DEVICE_FAMILIES) clean end @@ -32,6 +33,7 @@ all: begin $(DEVICE_FAMILIES) clean end arch_avr8: begin $(AVR8_FAMILIES:%=%.avr8) end arch_xmega: begin $(XMEGA_FAMILIES:%=%.xmega) end arch_uc3: begin $(UC3_FAMILIES:%=%.uc3) end +arch_avrdx: begin $(AVRDX_FAMILIES:%=%.avrdx) end begin: @echo Executing build test "ModuleTest". @@ -53,14 +55,19 @@ end: @echo Building ModuleTest for ARCH=UC3 MCU=$(@:%.uc3=%)... $(MAKE) -f makefile.test clean elf ARCH=UC3 MCU=$(@:%.uc3=%) +%.avrdx: + @echo Building ModuleTest for ARCH=AVRDX MCU=$(@:%.avrdx=%)... + $(MAKE) -f makefile.test clean elf ARCH=AVRDX MCU=$(@:%.avrdx=%) + clean: $(MAKE) -f makefile.test clean ARCH=AVR8 MCU=$(firstword $(AVR8_FAMILIES)) $(MAKE) -f makefile.test clean ARCH=XMEGA MCU=$(firstword $(XMEGA_FAMILIES)) $(MAKE) -f makefile.test clean ARCH=UC3 MCU=$(firstword $(UC3_FAMILIES)) + $(MAKE) -f makefile.test clean ARCH=AVRDX MCU=$(firstword $(AVRDX_FAMILIES)) %: -.PHONY: all arch_avr8 arch_xmega arch_uc3 begin end +.PHONY: all arch_avr8 arch_xmega arch_uc3 arch_avrdx begin end # Include common DMBS build system modules DMBS_PATH ?= $(LUFA_PATH)/Build/DMBS/DMBS diff --git a/BuildTests/ModuleTest/makefile.test b/BuildTests/ModuleTest/makefile.test index 7c442aaa3..881912b8c 100644 --- a/BuildTests/ModuleTest/makefile.test +++ b/BuildTests/ModuleTest/makefile.test @@ -27,6 +27,8 @@ else ifeq ($(ARCH), XMEGA) F_USB = 48000000 else ifeq ($(ARCH), UC3) F_USB = 48000000 +else ifeq ($(ARCH), AVRDX) + F_USB = 48000000 endif # Generic C/C++ compiler flags diff --git a/BuildTests/SingleUSBModeTest/makefile b/BuildTests/SingleUSBModeTest/makefile index 08b4a8ebf..c61789b35 100644 --- a/BuildTests/SingleUSBModeTest/makefile +++ b/BuildTests/SingleUSBModeTest/makefile @@ -43,10 +43,14 @@ compile: @echo Building SingleUSBModeTest for ARCH=UC3 in host only mode... $(MAKE) -f makefile.test clean elf ARCH=UC3 MCU=uc3a0256 CC_FLAGS='-D USB_HOST_ONLY' + @echo Building SingleUSBModeTest for ARCH=AVRDX in device only mode... + $(MAKE) -f makefile.test clean elf ARCH=AVRDX MCU=avr64du32 CC_FLAGS='-D USB_DEVICE_ONLY' + clean: $(MAKE) -f makefile.test clean ARCH=AVR8 MCU=at90usb1287 $(MAKE) -f makefile.test clean ARCH=XMEGA MCU=atxmega128a1u $(MAKE) -f makefile.test clean ARCH=UC3 MCU=uc3a0256 + $(MAKE) -f makefile.test clean ARCH=AVRDX MCU=avr64du32 %: diff --git a/BuildTests/SingleUSBModeTest/makefile.test b/BuildTests/SingleUSBModeTest/makefile.test index 80c0c4327..1f20f808e 100644 --- a/BuildTests/SingleUSBModeTest/makefile.test +++ b/BuildTests/SingleUSBModeTest/makefile.test @@ -23,6 +23,8 @@ else ifeq ($(ARCH), XMEGA) F_USB = 48000000 else ifeq ($(ARCH), UC3) F_USB = 48000000 +else ifeq ($(ARCH), AVRDX) + F_USB = 48000000 endif OPTIMIZATION = 1 diff --git a/Demos/Device/ClassDriver/CCID/CCID.c b/Demos/Device/ClassDriver/CCID/CCID.c index 18e8e6c0a..66a70fcc4 100644 --- a/Demos/Device/ClassDriver/CCID/CCID.c +++ b/Demos/Device/ClassDriver/CCID/CCID.c @@ -113,6 +113,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/CCID/CCID.txt b/Demos/Device/ClassDriver/CCID/CCID.txt index b59c6dc23..e3bdef8bd 100644 --- a/Demos/Device/ClassDriver/CCID/CCID.txt +++ b/Demos/Device/ClassDriver/CCID/CCID.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/CCID/Config/LUFAConfig.h b/Demos/Device/ClassDriver/CCID/Config/LUFAConfig.h index 819776904..615b4a1bd 100644 --- a/Demos/Device/ClassDriver/CCID/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/CCID/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/DualMIDI/Config/LUFAConfig.h b/Demos/Device/ClassDriver/DualMIDI/Config/LUFAConfig.h index e7bfcba95..a5453ace4 100644 --- a/Demos/Device/ClassDriver/DualMIDI/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/DualMIDI/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 2 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 2 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/DualMIDI/DualMIDI.c b/Demos/Device/ClassDriver/DualMIDI/DualMIDI.c index 7d5f9ff5f..a9be42acf 100644 --- a/Demos/Device/ClassDriver/DualMIDI/DualMIDI.c +++ b/Demos/Device/ClassDriver/DualMIDI/DualMIDI.c @@ -109,6 +109,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/DualMIDI/DualMIDI.txt b/Demos/Device/ClassDriver/DualMIDI/DualMIDI.txt index 19d4dbc04..7ff0dd1d6 100644 --- a/Demos/Device/ClassDriver/DualMIDI/DualMIDI.txt +++ b/Demos/Device/ClassDriver/DualMIDI/DualMIDI.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/Config/LUFAConfig.h b/Demos/Device/ClassDriver/DualVirtualSerial/Config/LUFAConfig.h index d84a43091..b67843729 100644 --- a/Demos/Device/ClassDriver/DualVirtualSerial/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/DualVirtualSerial/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 6 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 6 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c index c66ce730b..fe2c734c9 100644 --- a/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c +++ b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c @@ -148,6 +148,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt index c325e9ced..bf27ef67f 100644 --- a/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt +++ b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt @@ -16,6 +16,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/GenericHID/Config/LUFAConfig.h b/Demos/Device/ClassDriver/GenericHID/Config/LUFAConfig.h index 477b27f77..58899b7e7 100644 --- a/Demos/Device/ClassDriver/GenericHID/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/GenericHID/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 1 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 1 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/GenericHID/GenericHID.c b/Demos/Device/ClassDriver/GenericHID/GenericHID.c index bd6c3f6ad..79eabb84f 100644 --- a/Demos/Device/ClassDriver/GenericHID/GenericHID.c +++ b/Demos/Device/ClassDriver/GenericHID/GenericHID.c @@ -97,6 +97,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/GenericHID/GenericHID.txt b/Demos/Device/ClassDriver/GenericHID/GenericHID.txt index 0d780f49d..d5cb09749 100644 --- a/Demos/Device/ClassDriver/GenericHID/GenericHID.txt +++ b/Demos/Device/ClassDriver/GenericHID/GenericHID.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/Joystick/Config/LUFAConfig.h b/Demos/Device/ClassDriver/Joystick/Config/LUFAConfig.h index 477b27f77..58899b7e7 100644 --- a/Demos/Device/ClassDriver/Joystick/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/Joystick/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 1 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 1 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/Joystick/Joystick.c b/Demos/Device/ClassDriver/Joystick/Joystick.c index c0efd78bb..32e8b3877 100644 --- a/Demos/Device/ClassDriver/Joystick/Joystick.c +++ b/Demos/Device/ClassDriver/Joystick/Joystick.c @@ -97,6 +97,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/Joystick/Joystick.txt b/Demos/Device/ClassDriver/Joystick/Joystick.txt index b174642f4..a372f0413 100644 --- a/Demos/Device/ClassDriver/Joystick/Joystick.txt +++ b/Demos/Device/ClassDriver/Joystick/Joystick.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/Keyboard/Config/LUFAConfig.h b/Demos/Device/ClassDriver/Keyboard/Config/LUFAConfig.h index 477b27f77..58899b7e7 100644 --- a/Demos/Device/ClassDriver/Keyboard/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/Keyboard/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 1 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 1 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/Keyboard/Keyboard.c b/Demos/Device/ClassDriver/Keyboard/Keyboard.c index a4c27cf8b..440549fea 100644 --- a/Demos/Device/ClassDriver/Keyboard/Keyboard.c +++ b/Demos/Device/ClassDriver/Keyboard/Keyboard.c @@ -97,6 +97,10 @@ void SetupHardware() XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/Keyboard/Keyboard.txt b/Demos/Device/ClassDriver/Keyboard/Keyboard.txt index 3813745c8..35f7bdfdd 100644 --- a/Demos/Device/ClassDriver/Keyboard/Keyboard.txt +++ b/Demos/Device/ClassDriver/Keyboard/Keyboard.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/KeyboardMouse/Config/LUFAConfig.h b/Demos/Device/ClassDriver/KeyboardMouse/Config/LUFAConfig.h index 31fc30c4e..27ac4edba 100644 --- a/Demos/Device/ClassDriver/KeyboardMouse/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/KeyboardMouse/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 3 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 3 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c b/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c index a38d25011..a57c37867 100644 --- a/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c +++ b/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c @@ -123,6 +123,10 @@ void SetupHardware() XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.txt b/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.txt index 262a84f0e..cc8b7e593 100644 --- a/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.txt +++ b/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/KeyboardMouseMultiReport/Config/LUFAConfig.h b/Demos/Device/ClassDriver/KeyboardMouseMultiReport/Config/LUFAConfig.h index 477b27f77..58899b7e7 100644 --- a/Demos/Device/ClassDriver/KeyboardMouseMultiReport/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/KeyboardMouseMultiReport/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 1 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 1 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/KeyboardMouseMultiReport/KeyboardMouseMultiReport.c b/Demos/Device/ClassDriver/KeyboardMouseMultiReport/KeyboardMouseMultiReport.c index c96efed63..100298f10 100644 --- a/Demos/Device/ClassDriver/KeyboardMouseMultiReport/KeyboardMouseMultiReport.c +++ b/Demos/Device/ClassDriver/KeyboardMouseMultiReport/KeyboardMouseMultiReport.c @@ -97,6 +97,10 @@ void SetupHardware() XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/KeyboardMouseMultiReport/KeyboardMouseMultiReport.txt b/Demos/Device/ClassDriver/KeyboardMouseMultiReport/KeyboardMouseMultiReport.txt index ed55f595a..07542f98c 100644 --- a/Demos/Device/ClassDriver/KeyboardMouseMultiReport/KeyboardMouseMultiReport.txt +++ b/Demos/Device/ClassDriver/KeyboardMouseMultiReport/KeyboardMouseMultiReport.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/MIDI/Config/LUFAConfig.h b/Demos/Device/ClassDriver/MIDI/Config/LUFAConfig.h index e7bfcba95..a5453ace4 100644 --- a/Demos/Device/ClassDriver/MIDI/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/MIDI/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 2 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 2 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/MIDI/MIDI.c b/Demos/Device/ClassDriver/MIDI/MIDI.c index 8bf016860..150445f04 100644 --- a/Demos/Device/ClassDriver/MIDI/MIDI.c +++ b/Demos/Device/ClassDriver/MIDI/MIDI.c @@ -109,6 +109,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/MIDI/MIDI.txt b/Demos/Device/ClassDriver/MIDI/MIDI.txt index 97a92a190..9a8d08511 100644 --- a/Demos/Device/ClassDriver/MIDI/MIDI.txt +++ b/Demos/Device/ClassDriver/MIDI/MIDI.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/MassStorage/Config/LUFAConfig.h b/Demos/Device/ClassDriver/MassStorage/Config/LUFAConfig.h index 819776904..615b4a1bd 100644 --- a/Demos/Device/ClassDriver/MassStorage/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/MassStorage/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/MassStorage/MassStorage.c b/Demos/Device/ClassDriver/MassStorage/MassStorage.c index f67f979c4..8315cbf98 100644 --- a/Demos/Device/ClassDriver/MassStorage/MassStorage.c +++ b/Demos/Device/ClassDriver/MassStorage/MassStorage.c @@ -99,6 +99,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/MassStorage/MassStorage.txt b/Demos/Device/ClassDriver/MassStorage/MassStorage.txt index 5759efa6b..1eac292d5 100644 --- a/Demos/Device/ClassDriver/MassStorage/MassStorage.txt +++ b/Demos/Device/ClassDriver/MassStorage/MassStorage.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/MassStorageKeyboard/Config/LUFAConfig.h b/Demos/Device/ClassDriver/MassStorageKeyboard/Config/LUFAConfig.h index 304a9016b..311483f44 100644 --- a/Demos/Device/ClassDriver/MassStorageKeyboard/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/MassStorageKeyboard/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 5 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 5 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c b/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c index d0ef343ba..73341bb2c 100644 --- a/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c +++ b/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c @@ -123,6 +123,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.txt b/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.txt index d8b3b31db..98dc3e208 100644 --- a/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.txt +++ b/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/Mouse/Config/LUFAConfig.h b/Demos/Device/ClassDriver/Mouse/Config/LUFAConfig.h index 477b27f77..58899b7e7 100644 --- a/Demos/Device/ClassDriver/Mouse/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/Mouse/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 1 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 1 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/Mouse/Mouse.c b/Demos/Device/ClassDriver/Mouse/Mouse.c index 8af40fa26..cc8199161 100644 --- a/Demos/Device/ClassDriver/Mouse/Mouse.c +++ b/Demos/Device/ClassDriver/Mouse/Mouse.c @@ -97,6 +97,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/Mouse/Mouse.txt b/Demos/Device/ClassDriver/Mouse/Mouse.txt index dc65b8879..3145f8c1b 100644 --- a/Demos/Device/ClassDriver/Mouse/Mouse.txt +++ b/Demos/Device/ClassDriver/Mouse/Mouse.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/RNDISEthernet/Config/LUFAConfig.h b/Demos/Device/ClassDriver/RNDISEthernet/Config/LUFAConfig.h index 31fc30c4e..27ac4edba 100644 --- a/Demos/Device/ClassDriver/RNDISEthernet/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/RNDISEthernet/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 3 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 3 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.c b/Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.c index 1ceb6182a..4b5c6a57f 100644 --- a/Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.c +++ b/Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.c @@ -134,6 +134,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.txt b/Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.txt index c926ddae5..d6275fc53 100644 --- a/Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.txt +++ b/Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.txt @@ -15,6 +15,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/VirtualSerial/Config/LUFAConfig.h b/Demos/Device/ClassDriver/VirtualSerial/Config/LUFAConfig.h index 819776904..615b4a1bd 100644 --- a/Demos/Device/ClassDriver/VirtualSerial/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/VirtualSerial/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c index 8c787a196..1592f3497 100644 --- a/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c +++ b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c @@ -117,6 +117,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt index c802d9950..0eac3ce87 100644 --- a/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt +++ b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/VirtualSerialMassStorage/Config/LUFAConfig.h b/Demos/Device/ClassDriver/VirtualSerialMassStorage/Config/LUFAConfig.h index 304a9016b..311483f44 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMassStorage/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/VirtualSerialMassStorage/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 5 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 5 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.c b/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.c index d60d8c47f..05e2261e4 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.c +++ b/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.c @@ -143,6 +143,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.txt b/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.txt index 246775c22..736fa2965 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.txt +++ b/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.txt @@ -16,6 +16,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/Config/LUFAConfig.h b/Demos/Device/ClassDriver/VirtualSerialMouse/Config/LUFAConfig.h index 819776904..615b4a1bd 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/Config/LUFAConfig.h +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c index 1a1bb7ed1..b4353ab8e 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c @@ -133,6 +133,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt index 97ba8714e..7064a2761 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt @@ -16,6 +16,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/Incomplete/TestAndMeasurement/Config/LUFAConfig.h b/Demos/Device/Incomplete/TestAndMeasurement/Config/LUFAConfig.h index 819776904..615b4a1bd 100644 --- a/Demos/Device/Incomplete/TestAndMeasurement/Config/LUFAConfig.h +++ b/Demos/Device/Incomplete/TestAndMeasurement/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c index 8a314146c..a172908c4 100644 --- a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c +++ b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c @@ -110,6 +110,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/BulkVendor/BulkVendor.c b/Demos/Device/LowLevel/BulkVendor/BulkVendor.c index ddcabe3ba..b0a7561e2 100644 --- a/Demos/Device/LowLevel/BulkVendor/BulkVendor.c +++ b/Demos/Device/LowLevel/BulkVendor/BulkVendor.c @@ -88,6 +88,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/BulkVendor/BulkVendor.txt b/Demos/Device/LowLevel/BulkVendor/BulkVendor.txt index d6688a9cd..0962e79eb 100644 --- a/Demos/Device/LowLevel/BulkVendor/BulkVendor.txt +++ b/Demos/Device/LowLevel/BulkVendor/BulkVendor.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/BulkVendor/Config/LUFAConfig.h b/Demos/Device/LowLevel/BulkVendor/Config/LUFAConfig.h index 819776904..615b4a1bd 100644 --- a/Demos/Device/LowLevel/BulkVendor/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/BulkVendor/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/CCID/CCID.c b/Demos/Device/LowLevel/CCID/CCID.c index c21462df4..dc166024e 100644 --- a/Demos/Device/LowLevel/CCID/CCID.c +++ b/Demos/Device/LowLevel/CCID/CCID.c @@ -99,6 +99,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/CCID/CCID.txt b/Demos/Device/LowLevel/CCID/CCID.txt index b59c6dc23..e3bdef8bd 100644 --- a/Demos/Device/LowLevel/CCID/CCID.txt +++ b/Demos/Device/LowLevel/CCID/CCID.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/CCID/Config/LUFAConfig.h b/Demos/Device/LowLevel/CCID/Config/LUFAConfig.h index 819776904..615b4a1bd 100644 --- a/Demos/Device/LowLevel/CCID/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/CCID/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/DualVirtualSerial/Config/LUFAConfig.h b/Demos/Device/LowLevel/DualVirtualSerial/Config/LUFAConfig.h index d84a43091..b67843729 100644 --- a/Demos/Device/LowLevel/DualVirtualSerial/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/DualVirtualSerial/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 6 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 6 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c index 8869d9779..f644f7672 100644 --- a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c +++ b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c @@ -101,6 +101,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt index fb763b7a2..95429d98f 100644 --- a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt +++ b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt @@ -16,6 +16,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/GenericHID/Config/LUFAConfig.h b/Demos/Device/LowLevel/GenericHID/Config/LUFAConfig.h index e7bfcba95..a5453ace4 100644 --- a/Demos/Device/LowLevel/GenericHID/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/GenericHID/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 2 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 2 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/GenericHID/GenericHID.c b/Demos/Device/LowLevel/GenericHID/GenericHID.c index 453d0b135..2a07a179e 100644 --- a/Demos/Device/LowLevel/GenericHID/GenericHID.c +++ b/Demos/Device/LowLevel/GenericHID/GenericHID.c @@ -74,6 +74,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/GenericHID/GenericHID.txt b/Demos/Device/LowLevel/GenericHID/GenericHID.txt index 0d780f49d..d5cb09749 100644 --- a/Demos/Device/LowLevel/GenericHID/GenericHID.txt +++ b/Demos/Device/LowLevel/GenericHID/GenericHID.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/Joystick/Config/LUFAConfig.h b/Demos/Device/LowLevel/Joystick/Config/LUFAConfig.h index 477b27f77..58899b7e7 100644 --- a/Demos/Device/LowLevel/Joystick/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/Joystick/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 1 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 1 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/Joystick/Joystick.c b/Demos/Device/LowLevel/Joystick/Joystick.c index db39961cc..c27472149 100644 --- a/Demos/Device/LowLevel/Joystick/Joystick.c +++ b/Demos/Device/LowLevel/Joystick/Joystick.c @@ -73,6 +73,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/Joystick/Joystick.txt b/Demos/Device/LowLevel/Joystick/Joystick.txt index b174642f4..a372f0413 100644 --- a/Demos/Device/LowLevel/Joystick/Joystick.txt +++ b/Demos/Device/LowLevel/Joystick/Joystick.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/Keyboard/Config/LUFAConfig.h b/Demos/Device/LowLevel/Keyboard/Config/LUFAConfig.h index e7bfcba95..a5453ace4 100644 --- a/Demos/Device/LowLevel/Keyboard/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/Keyboard/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 2 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 2 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/Keyboard/Keyboard.c b/Demos/Device/LowLevel/Keyboard/Keyboard.c index a71129e4d..365e75c8e 100644 --- a/Demos/Device/LowLevel/Keyboard/Keyboard.c +++ b/Demos/Device/LowLevel/Keyboard/Keyboard.c @@ -91,6 +91,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/Keyboard/Keyboard.txt b/Demos/Device/LowLevel/Keyboard/Keyboard.txt index e945dccfe..1458e9905 100644 --- a/Demos/Device/LowLevel/Keyboard/Keyboard.txt +++ b/Demos/Device/LowLevel/Keyboard/Keyboard.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/KeyboardMouse/Config/LUFAConfig.h b/Demos/Device/LowLevel/KeyboardMouse/Config/LUFAConfig.h index 31fc30c4e..27ac4edba 100644 --- a/Demos/Device/LowLevel/KeyboardMouse/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/KeyboardMouse/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 3 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 3 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c index 4205b5e7f..70f539eea 100644 --- a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c +++ b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c @@ -82,6 +82,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.txt b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.txt index 262a84f0e..cc8b7e593 100644 --- a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.txt +++ b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/MIDI/Config/LUFAConfig.h b/Demos/Device/LowLevel/MIDI/Config/LUFAConfig.h index e7bfcba95..a5453ace4 100644 --- a/Demos/Device/LowLevel/MIDI/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/MIDI/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 2 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 2 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/MIDI/MIDI.c b/Demos/Device/LowLevel/MIDI/MIDI.c index 39ce5c775..66ddc1486 100644 --- a/Demos/Device/LowLevel/MIDI/MIDI.c +++ b/Demos/Device/LowLevel/MIDI/MIDI.c @@ -73,6 +73,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/MIDI/MIDI.txt b/Demos/Device/LowLevel/MIDI/MIDI.txt index 97a92a190..9a8d08511 100644 --- a/Demos/Device/LowLevel/MIDI/MIDI.txt +++ b/Demos/Device/LowLevel/MIDI/MIDI.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/MassStorage/Config/LUFAConfig.h b/Demos/Device/LowLevel/MassStorage/Config/LUFAConfig.h index 819776904..615b4a1bd 100644 --- a/Demos/Device/LowLevel/MassStorage/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/MassStorage/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/MassStorage/MassStorage.c b/Demos/Device/LowLevel/MassStorage/MassStorage.c index 4435d035d..4f02dd225 100644 --- a/Demos/Device/LowLevel/MassStorage/MassStorage.c +++ b/Demos/Device/LowLevel/MassStorage/MassStorage.c @@ -84,6 +84,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/MassStorage/MassStorage.txt b/Demos/Device/LowLevel/MassStorage/MassStorage.txt index b070dc83a..de1d1f815 100644 --- a/Demos/Device/LowLevel/MassStorage/MassStorage.txt +++ b/Demos/Device/LowLevel/MassStorage/MassStorage.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/Mouse/Config/LUFAConfig.h b/Demos/Device/LowLevel/Mouse/Config/LUFAConfig.h index 477b27f77..58899b7e7 100644 --- a/Demos/Device/LowLevel/Mouse/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/Mouse/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 1 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 1 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/Mouse/Mouse.c b/Demos/Device/LowLevel/Mouse/Mouse.c index c03bf6d90..4bd0849cb 100644 --- a/Demos/Device/LowLevel/Mouse/Mouse.c +++ b/Demos/Device/LowLevel/Mouse/Mouse.c @@ -90,6 +90,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/Mouse/Mouse.txt b/Demos/Device/LowLevel/Mouse/Mouse.txt index 7246ede31..e7139221e 100644 --- a/Demos/Device/LowLevel/Mouse/Mouse.txt +++ b/Demos/Device/LowLevel/Mouse/Mouse.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/RNDISEthernet/Config/LUFAConfig.h b/Demos/Device/LowLevel/RNDISEthernet/Config/LUFAConfig.h index 31fc30c4e..27ac4edba 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 3 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 3 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c index ec6c08912..cb277d52f 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c +++ b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c @@ -80,6 +80,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.txt b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.txt index c926ddae5..d6275fc53 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.txt +++ b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.txt @@ -15,6 +15,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/Demos/Device/LowLevel/VirtualSerial/Config/LUFAConfig.h b/Demos/Device/LowLevel/VirtualSerial/Config/LUFAConfig.h index efc5728b9..0fc078120 100644 --- a/Demos/Device/LowLevel/VirtualSerial/Config/LUFAConfig.h +++ b/Demos/Device/LowLevel/VirtualSerial/Config/LUFAConfig.h @@ -116,6 +116,39 @@ // #define CONTROL_ONLY_DEVICE #define MAX_ENDPOINT_INDEX 4 // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define USE_STATIC_OPTIONS (USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH) +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS + #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE + #define MAX_ENDPOINT_INDEX 4 +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #else diff --git a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c index 4ec570447..8b89ceaf5 100644 --- a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c +++ b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c @@ -87,6 +87,10 @@ void SetupHardware(void) XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; +#elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); #endif /* Hardware Initialization */ diff --git a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt index c802d9950..0eac3ce87 100644 --- a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt +++ b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt @@ -17,6 +17,7 @@ * \li Series AU XMEGA AVRs (ATXMEGAxxxAxU) * \li Series B XMEGA AVRs (ATXMEGAxxxBx) * \li Series C XMEGA AVRs (ATXMEGAxxxCx) + * \li Series DU AVRs (AVRxxDUxx) * * \section Sec_Info USB Information: * diff --git a/LUFA/Build/DMBS/DMBS/atprogram.mk b/LUFA/Build/DMBS/DMBS/atprogram.mk index 26addd6c6..0f2077401 100644 --- a/LUFA/Build/DMBS/DMBS/atprogram.mk +++ b/LUFA/Build/DMBS/DMBS/atprogram.mk @@ -42,7 +42,7 @@ endif ifeq ($(ARCH), AVR8) ATPROGRAM_FLASH_FLAGS := --chiperase --flash ATPROGRAM_EEPROM_FLAGS := --eeprom -else ifeq ($(ARCH), XMEGA) +else ifneq ($(findstring $(ARCH), XMEGA AVRDX),) ATPROGRAM_FLASH_FLAGS := --erase --flash ATPROGRAM_EEPROM_FLAGS := --eeprom else ifeq ($(ARCH), UC3) diff --git a/LUFA/Build/DMBS/DMBS/gcc.mk b/LUFA/Build/DMBS/DMBS/gcc.mk index 24c9b070b..a4b7dbde6 100644 --- a/LUFA/Build/DMBS/DMBS/gcc.mk +++ b/LUFA/Build/DMBS/DMBS/gcc.mk @@ -59,6 +59,8 @@ else ifeq ($(ARCH), XMEGA) CROSS := $(COMPILER_PATH)avr else ifeq ($(ARCH), UC3) CROSS := $(COMPILER_PATH)avr32 +else ifeq ($(ARCH), AVRDX) + CROSS := $(COMPILER_PATH)avr else $(error Unsupported architecture "$(ARCH)") endif @@ -109,7 +111,7 @@ DEPENDENCY_FILES := $(OBJECT_FILES:%.o=%.d) # Create a list of common flags to pass to the compiler/linker/assembler BASE_CC_FLAGS := -pipe -g$(DEBUG_FORMAT) -g$(DEBUG_LEVEL) -ifneq ($(findstring $(ARCH), AVR8 XMEGA),) +ifneq ($(findstring $(ARCH), AVR8 XMEGA AVRDX),) BASE_C_FLAGS += -fpack-struct BASE_CC_FLAGS += -mmcu=$(MCU) -fshort-enums -fno-inline-small-functions else ifneq ($(findstring $(ARCH), UC3),) @@ -143,7 +145,7 @@ BASE_LD_FLAGS := -lm -Wl,-Map=$(TARGET).map,--cref -Wl,--gc-sections ifeq ($(LINKER_RELAXATIONS), Y) BASE_LD_FLAGS += -Wl,--relax endif -ifneq ($(findstring $(ARCH), AVR8 XMEGA),) +ifneq ($(findstring $(ARCH), AVR8 XMEGA AVRDX),) BASE_LD_FLAGS += -mmcu=$(MCU) else ifneq ($(findstring $(ARCH), UC3),) BASE_LD_FLAGS += -mpart=$(MCU:at32%=%) --rodata-writable --direct-data diff --git a/LUFA/Build/LUFA/lufa-gcc.mk b/LUFA/Build/LUFA/lufa-gcc.mk index 0d51ca2b6..97e95a549 100644 --- a/LUFA/Build/LUFA/lufa-gcc.mk +++ b/LUFA/Build/LUFA/lufa-gcc.mk @@ -35,6 +35,8 @@ ifeq ($(ARCH), XMEGA) $(warning The XMEGA device support is currently EXPERIMENTAL (incomplete and/or non-functional), and is included for preview purposes only.) else ifeq ($(ARCH), UC3) $(warning The UC3 device support is currently EXPERIMENTAL (incomplete and/or non-functional), and is included for preview purposes only.) +else ifeq ($(ARCH), AVRDX) + $(warning The AVR Dx device support is currently EXPERIMENTAL (incomplete and/or non-functional), and is included for preview purposes only.) endif # Common LUFA C/C++ includes/definitions diff --git a/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c b/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c index 0f90e55bd..bed584ce4 100644 --- a/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c +++ b/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c @@ -78,6 +78,14 @@ void SetupHardware(void) /* Hardware Initialization */ USB_Init(USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH); + + #elif (ARCH == ARCH_AVRDX) + /* Configure the OSCHF to run at F_CPU with SOF Autotune enabled */ + AVRDXCLK_ConfigureOSCHF(F_CPU, AUTOTUNE_SOF_BIN); + AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); + + /* Hardware Initialization */ + USB_Init(USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH); #endif } diff --git a/LUFA/CodeTemplates/LUFAConfig.h b/LUFA/CodeTemplates/LUFAConfig.h index 1e44aa039..e6187627d 100644 --- a/LUFA/CodeTemplates/LUFAConfig.h +++ b/LUFA/CodeTemplates/LUFAConfig.h @@ -119,6 +119,39 @@ // #define CONTROL_ONLY_DEVICE // #define MAX_ENDPOINT_INDEX {Insert Value Here} // #define NO_DEVICE_REMOTE_WAKEUP +// #define NO_DEVICE_SELF_POWER + + #elif (ARCH == ARCH_AVRDX) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ +// #define USE_STATIC_OPTIONS {Insert Value Here} +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT +// #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ +// #define USE_RAM_DESCRIPTORS +// #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS +// #define NO_INTERNAL_SERIAL +// #define FIXED_CONTROL_ENDPOINT_SIZE {Insert Value Here} +// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} +// #define FIXED_NUM_CONFIGURATIONS {Insert Value Here} +// #define CONTROL_ONLY_DEVICE +// #define MAX_ENDPOINT_INDEX {Insert Value Here} +// #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER #elif (ARCH == ARCH_UC3) diff --git a/LUFA/Common/ArchitectureSpecific.h b/LUFA/Common/ArchitectureSpecific.h index 2d2f66256..da370d531 100644 --- a/LUFA/Common/ArchitectureSpecific.h +++ b/LUFA/Common/ArchitectureSpecific.h @@ -63,7 +63,7 @@ /* Public Interface - May be used in end-application: */ /* Macros: */ - #if (ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || defined(__DOXYGEN__) + #if (ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || (ARCH == ARCH_AVRDX) || defined(__DOXYGEN__) #if (ARCH == ARCH_AVR8) || defined(__DOXYGEN__) /** Re-enables the AVR's JTAG bus in software, until a system reset. This will re-enable JTAG debugging * interface after is has been disabled in software via \ref JTAG_DISABLE(). diff --git a/LUFA/Common/Architectures.h b/LUFA/Common/Architectures.h index 95b6626c5..9cf26942c 100644 --- a/LUFA/Common/Architectures.h +++ b/LUFA/Common/Architectures.h @@ -70,6 +70,9 @@ /** Selects the Atmel XMEGA AVR (ATXMEGA* chips) architecture. */ #define ARCH_XMEGA 2 + /** Selects the Microchip AVR Dx (AVR*D** chips) architecture. */ + #define ARCH_AVRDX 3 + #if !defined(__DOXYGEN__) #define ARCH_ ARCH_AVR8 diff --git a/LUFA/Common/BoardTypes.h b/LUFA/Common/BoardTypes.h index c641438e0..1e883da6b 100644 --- a/LUFA/Common/BoardTypes.h +++ b/LUFA/Common/BoardTypes.h @@ -252,6 +252,8 @@ /** Selects the Teensy version 2.x ++ specific board drivers, including the driver for the board LEDs. */ #define BOARD_TEENSY2PP 62 + /** Selects the AVR64DU32 specific board drivers, including the Button and LED drivers. */ + #define BOARD_AVR64DU32_CNANO 63 #if !defined(__DOXYGEN__) #define BOARD_ BOARD_NONE diff --git a/LUFA/Common/Common.h b/LUFA/Common/Common.h index be9d4afd9..2b739e1c4 100644 --- a/LUFA/Common/Common.h +++ b/LUFA/Common/Common.h @@ -124,7 +124,7 @@ #define ARCH_BIG_ENDIAN #include "Endianness.h" - #elif (ARCH == ARCH_XMEGA) + #elif ((ARCH == ARCH_XMEGA) || (ARCH == ARCH_AVRDX)) #include #include #include @@ -281,7 +281,7 @@ __builtin_mtsr(AVR32_COUNT, 0); while ((uint32_t)__builtin_mfsr(AVR32_COUNT) < (F_CPU / 1000)); } - #elif (ARCH == ARCH_XMEGA) + #elif ((ARCH == ARCH_XMEGA) || (ARCH == ARCH_AVRDX)) if (GCC_IS_COMPILE_CONST(Milliseconds)) { _delay_ms(Milliseconds); @@ -307,12 +307,10 @@ { GCC_MEMORY_BARRIER(); - #if (ARCH == ARCH_AVR8) + #if ((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || (ARCH == ARCH_AVRDX)) return SREG; #elif (ARCH == ARCH_UC3) return __builtin_mfsr(AVR32_SR); - #elif (ARCH == ARCH_XMEGA) - return SREG; #endif } @@ -329,15 +327,13 @@ { GCC_MEMORY_BARRIER(); - #if (ARCH == ARCH_AVR8) + #if ((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || (ARCH == ARCH_AVRDX)) SREG = GlobalIntState; #elif (ARCH == ARCH_UC3) if (GlobalIntState & AVR32_SR_GM) __builtin_ssrf(AVR32_SR_GM_OFFSET); else __builtin_csrf(AVR32_SR_GM_OFFSET); - #elif (ARCH == ARCH_XMEGA) - SREG = GlobalIntState; #endif GCC_MEMORY_BARRIER(); @@ -352,12 +348,10 @@ { GCC_MEMORY_BARRIER(); - #if (ARCH == ARCH_AVR8) + #if ((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || (ARCH == ARCH_AVRDX)) sei(); #elif (ARCH == ARCH_UC3) __builtin_csrf(AVR32_SR_GM_OFFSET); - #elif (ARCH == ARCH_XMEGA) - sei(); #endif GCC_MEMORY_BARRIER(); @@ -372,12 +366,10 @@ { GCC_MEMORY_BARRIER(); - #if (ARCH == ARCH_AVR8) + #if ((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || (ARCH == ARCH_AVRDX)) cli(); #elif (ARCH == ARCH_UC3) __builtin_ssrf(AVR32_SR_GM_OFFSET); - #elif (ARCH == ARCH_XMEGA) - cli(); #endif GCC_MEMORY_BARRIER(); diff --git a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h new file mode 100644 index 000000000..d9a6a8273 --- /dev/null +++ b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h @@ -0,0 +1,82 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific information header for the Microchip AVR64DU32 Curiosity Nano. + * \copydetails Group_BoardInfo_AVR64DU32_CNANO + * + * \note This file should not be included directly. It is automatically included as needed by the Board driver + * dispatch header located in LUFA/Drivers/Board/Board.h. + */ + +/** \ingroup Group_BoardInfo + * \defgroup Group_BoardInfo_AVR64DU32_CNANO AVR64DU32_CNANO + * \brief Board specific information header for the Microchip AVR64DU32 Curiosity Nano. + * + * Board specific information header for the Microchip AVR64DU32 Curiosity Nano. + * + * @{ + */ + +#ifndef __BOARD_AVR64DU32_CNANO_H__ +#define __BOARD_AVR64DU32_CNANO_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../../Buttons.h" + #include "../../LEDs.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_BOARD_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Board.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Indicates the board has hardware Buttons mounted. */ + #define BOARD_HAS_BUTTONS + + /** Indicates the board has hardware LEDs mounted. */ + #define BOARD_HAS_LEDS + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h new file mode 100644 index 000000000..2dc4eaab6 --- /dev/null +++ b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h @@ -0,0 +1,105 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific Buttons driver header for the Microchip AVR64DU32 Curiosity Nano. + * \copydetails Group_Buttons_AVR64DU32_CNANO + * + * \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_AVR64DU32_CNANO AVR64DU32_CNANO + * \brief Board specific Buttons driver header for the Microchip AVR64DU32 Curiosity Nano. + * + * Board specific Buttons driver header for the Microchip AVR64DU32 Curiosity Nano. + * + * + * + * + *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1SW0 ButtonLowPORTF.6
+ * + * @{ + */ + +#ifndef __BUTTONS_AVR64DU32_CNANO_H__ +#define __BUTTONS_AVR64DU32_CNANO_H__ + + /* Includes: */ + #include + + /* 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 PIN6_bm + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Buttons_Init(void) + { + PORTF.OUTCLR = BUTTONS_BUTTON1; + PORTF.PINCONFIG = (PORT_PULLUPEN_bm | PORT_INVEN_bm); + PORTF.PINCTRLUPD = BUTTONS_BUTTON1; + } + + static inline void Buttons_Disable(void) + { + PORTF.OUTCLR = BUTTONS_BUTTON1; + PORTF.PINCONFIG = 0; + PORTF.PINCTRLUPD = BUTTONS_BUTTON1; + } + + ATTR_WARN_UNUSED_RESULT + static inline uint8_t Buttons_GetStatus(void) + { + return (VPORTF.IN & BUTTONS_BUTTON1); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h new file mode 100644 index 000000000..94021e58b --- /dev/null +++ b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h @@ -0,0 +1,151 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Board specific LED driver header for the Microchip AVR64DU32 Curiosity Nano. + * \copydetails Group_LEDs_AVR64DU32_CNANO + * + * \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_AVR64DU32_CNANO AVR64DU32_CNANO + * \brief Board specific LED driver header for the Microchip AVR64DU32 Curiosity Nano. + * + * Board specific LED driver header for the Microchip AVR64DU32 Curiosity Nano. + * + * + * + * + *
NameColorInfoActive LevelPort Pin
LEDS_LED1YellowLED0 LEDLowPORTF.2
+ * + * @{ + */ + +#ifndef __LEDS_AVR64DU32_CNANO_H__ +#define __LEDS_AVR64DU32_CNANO_H__ + + /* Includes: */ + #include + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_LEDS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define LEDS_PORTF_LEDS (LEDS_LED1) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** LED mask for the first LED on the board. */ + #define LEDS_LED1 PIN2_bm + + /** 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) + { + PORTF.DIRSET = LEDS_PORTF_LEDS; + PORTF.OUTCLR = LEDS_PORTF_LEDS; + + PORTF.PINCONFIG = PORT_INVEN_bm; + PORTF.PINCTRLUPD = LEDS_PORTF_LEDS; + } + + static inline void LEDs_Disable(void) + { + PORTF.DIRCLR = LEDS_PORTF_LEDS; + PORTF.OUTCLR = LEDS_PORTF_LEDS; + + PORTF.PINCONFIG = 0; + PORTF.PINCTRLUPD = LEDS_PORTF_LEDS; + } + + static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) + { + PORTF.OUTSET = LEDMask & LEDS_PORTF_LEDS; + } + + static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) + { + PORTF.OUTCLR = LEDMask & LEDS_PORTF_LEDS; + } + + static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) + { + PORTF.OUTCLR = LEDS_PORTF_LEDS; + + PORTF.OUTSET = (LEDMask & LEDS_PORTF_LEDS); + } + + static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, + const uint8_t ActiveMask) + { + PORTF.OUTCLR = (LEDMask & LEDS_PORTF_LEDS); + + PORTF.OUTSET = (ActiveMask & LEDS_PORTF_LEDS); + } + + static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) + { + PORTF.OUTTGL = (LEDMask & LEDS_PORTF_LEDS); + } + + ATTR_WARN_UNUSED_RESULT + static inline uint8_t LEDs_GetLEDs(void) + { + return (PORTF.OUT & LEDS_PORTF_LEDS); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Board/Board.h b/LUFA/Drivers/Board/Board.h index fc6c3f2d3..af28f7334 100644 --- a/LUFA/Drivers/Board/Board.h +++ b/LUFA/Drivers/Board/Board.h @@ -162,6 +162,8 @@ #include "AVR8/POLOLUMICRO/Board.h" #elif (BOARD == BOARD_XPLAINED_MINI) #include "AVR8/XPLAINED_MINI/Board.h" + #elif (BOARD == BOARD_AVR64DU32_CNANO) + #include "AVRDX/AVR64DU32_CNANO/Board.h" #else #include "Board/Board.h" #endif diff --git a/LUFA/Drivers/Board/Buttons.h b/LUFA/Drivers/Board/Buttons.h index 196a25e3a..2d6f7bbb7 100644 --- a/LUFA/Drivers/Board/Buttons.h +++ b/LUFA/Drivers/Board/Buttons.h @@ -95,7 +95,7 @@ #define BUTTONS_BUTTON1 0 static inline void Buttons_Init(void) {} static inline void Buttons_Disable(void) {} - { return 0 } + static inline uint8_t Buttons_GetStatus(void) { return 0; } #elif (BOARD == BOARD_USBKEY) #include "AVR8/USBKEY/Buttons.h" #elif (BOARD == BOARD_STK525) @@ -160,6 +160,8 @@ #include "XMEGA/C3_XPLAINED/Buttons.h" #elif (BOARD == BOARD_U2S) #include "AVR8/U2S/Buttons.h" + #elif (BOARD == BOARD_AVR64DU32_CNANO) + #include "AVRDX/AVR64DU32_CNANO/Buttons.h" #else #include "Board/Buttons.h" #endif diff --git a/LUFA/Drivers/Board/LEDs.h b/LUFA/Drivers/Board/LEDs.h index b9db3a644..c7a8f55cb 100644 --- a/LUFA/Drivers/Board/LEDs.h +++ b/LUFA/Drivers/Board/LEDs.h @@ -212,6 +212,8 @@ #include "AVR8/POLOLUMICRO/LEDs.h" #elif (BOARD == BOARD_XPLAINED_MINI) #include "AVR8/XPLAINED_MINI/LEDs.h" + #elif (BOARD == BOARD_AVR64DU32_CNANO) + #include "AVRDX/AVR64DU32_CNANO/LEDs.h" #else #include "Board/LEDs.h" #endif diff --git a/LUFA/Drivers/Peripheral/AVRDX/SPI_AVRDX.h b/LUFA/Drivers/Peripheral/AVRDX/SPI_AVRDX.h new file mode 100644 index 000000000..617a88931 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVRDX/SPI_AVRDX.h @@ -0,0 +1,251 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief SPI Peripheral Driver (AVR Dx) + * + * On-chip SPI driver for the AVR Dx microcontrollers. + * + * \note This file should not be included directly. It is automatically included as needed by the SPI driver + * dispatch header located in LUFA/Drivers/Peripheral/SPI.h. + */ + +/** \ingroup Group_SPI + * \defgroup Group_SPI_AVRDX SPI Peripheral Driver (AVR Dx) + * + * \section Sec_SPI_AVRDX_ModDescription Module Description + * Driver for the hardware SPI port(s) available on AVR Dx microcontroller models. This + * module provides an easy to use driver for the setup and transfer of data over the AVR's + * SPI ports. + * + * \note This file should not be included directly. It is automatically included as needed by the SPI driver + * dispatch header located in LUFA/Drivers/Peripheral/SPI.h. + * + * \code + * // Initialize the SPI driver before first use + * SPI_Init(&SPIC, + * SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_FALLING | + * SPI_SAMPLE_TRAILING | SPI_MODE_MASTER); + * + * // Send several bytes, ignoring the returned data + * SPI_SendByte(&SPIC, 0x01); + * SPI_SendByte(&SPIC, 0x02); + * SPI_SendByte(&SPIC, 0x03); + * + * // Receive several bytes, sending a dummy 0x00 byte each time + * uint8_t Byte1 = SPI_ReceiveByte(&SPIC); + * uint8_t Byte2 = SPI_ReceiveByte(&SPIC); + * uint8_t Byte3 = SPI_ReceiveByte(&SPIC); + * + * // Send a byte, and store the received byte from the same transaction + * uint8_t ResponseByte = SPI_TransferByte(&SPIC, 0xDC); + * \endcode + * + * @{ + */ + +#ifndef __SPI_AVRDX_H__ +#define __SPI_AVRDX_H__ + + /* Includes: */ + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_SPI_H) + #error Do not include this file directly. Include LUFA/Drivers/Peripheral/SPI.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define SPI_USE_DOUBLESPEED SPI_CLK2X_bm + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** \name SPI Prescaler Configuration Masks */ + /**@{*/ + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 2. */ + #define SPI_SPEED_FCPU_DIV_2 SPI_USE_DOUBLESPEED + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 4. */ + #define SPI_SPEED_FCPU_DIV_4 0 + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 8. */ + #define SPI_SPEED_FCPU_DIV_8 (SPI_USE_DOUBLESPEED | SPI_PRESC_DIV16_gc) + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 16. */ + #define SPI_SPEED_FCPU_DIV_16 SPI_PRESC_DIV16_gc + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 32. */ + #define SPI_SPEED_FCPU_DIV_32 (SPI_USE_DOUBLESPEED | SPI_PRESC_DIV64_gc) + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 64. */ + #define SPI_SPEED_FCPU_DIV_64 SPI_PRESC_DIV64_gc + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 128. */ + #define SPI_SPEED_FCPU_DIV_128 SPI_PRESC_DIV128_gc + /**@}*/ + + /** \name SPI SCK Polarity Configuration Masks */ + /**@{*/ + /** SPI clock polarity mask for \ref SPI_Init(). Indicates that the SCK should lead on the rising edge. */ + #define SPI_SCK_LEAD_RISING 0 + + /** SPI clock polarity mask for \ref SPI_Init(). Indicates that the SCK should lead on the falling edge. */ + #define SPI_SCK_LEAD_FALLING SPI_MODE_1_bm + /**@}*/ + + /** \name SPI Sample Edge Configuration Masks */ + /**@{*/ + /** SPI data sample mode mask for \ref SPI_Init(). Indicates that the data should sampled on the leading edge. */ + #define SPI_SAMPLE_LEADING 0 + + /** SPI data sample mode mask for \ref SPI_Init(). Indicates that the data should be sampled on the trailing edge. */ + #define SPI_SAMPLE_TRAILING SPI_MODE_0_bm + /**@}*/ + + /** \name SPI Data Ordering Configuration Masks */ + /**@{*/ + /** SPI data order mask for \ref SPI_Init(). Indicates that data should be shifted out MSB first. */ + #define SPI_ORDER_MSB_FIRST 0 + + /** SPI data order mask for \ref SPI_Init(). Indicates that data should be shifted out LSB first. */ + #define SPI_ORDER_LSB_FIRST SPI_DORD_bm + /**@}*/ + + /** \name SPI Mode Configuration Masks */ + /**@{*/ + /** SPI mode mask for \ref SPI_Init(). Indicates that the SPI interface should be initialized into slave mode. */ + #define SPI_MODE_SLAVE 0 + + /** SPI mode mask for \ref SPI_Init(). Indicates that the SPI interface should be initialized into master mode. */ + #define SPI_MODE_MASTER SPI_MASTER_bm + /**@}*/ + + /* Inline Functions: */ + /** Initializes the SPI subsystem, ready for transfers. Must be called before calling any other + * SPI routines. + * + * \param[in,out] SPI Pointer to the base of the SPI peripheral within the device. + * \param[in] SPIOptions SPI Options, a mask consisting of one of each of the \c SPI_SPEED_*, + * \c SPI_SCK_*, \c SPI_SAMPLE_*, \c SPI_ORDER_* and \c SPI_MODE_* masks. + */ + static inline void SPI_Init(SPI_t* const SPI, + const uint8_t SPIOptions) ATTR_NON_NULL_PTR_ARG(1); + static inline void SPI_Init(SPI_t* const SPI, + const uint8_t SPIOptions) + { + SPI->CTRLA = (SPIOptions | SPI_ENABLE_bm); + } + + /** Turns off the SPI driver, disabling and returning used hardware to their default configuration. + * + * \param[in,out] SPI Pointer to the base of the SPI peripheral within the device. + */ + ATTR_NON_NULL_PTR_ARG(1) + static inline void SPI_Disable(SPI_t* const SPI) + { + SPI->CTRLA &= ~SPI_ENABLE_bm; + } + + /** Retrieves the currently selected SPI mode, once the SPI interface has been configured. + * + * \param[in,out] SPI Pointer to the base of the SPI peripheral within the device. + * + * \return \ref SPI_MODE_MASTER if the interface is currently in SPI Master mode, \ref SPI_MODE_SLAVE otherwise + */ + ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) + static inline uint8_t SPI_GetCurrentMode(SPI_t* const SPI) + { + return (SPI->CTRLA & SPI_MASTER_bm); + } + + /** Sends and receives a byte through the SPI interface, blocking until the transfer is complete. + * + * \param[in,out] SPI Pointer to the base of the SPI peripheral within the device. + * \param[in] Byte Byte to send through the SPI interface. + * + * \return Response byte from the attached SPI device. + */ + static inline uint8_t SPI_TransferByte(SPI_t* const SPI, + const uint8_t Byte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1); + static inline uint8_t SPI_TransferByte(SPI_t* const SPI, + const uint8_t Byte) + { + SPI->DATA = Byte; + while (!(SPI->INTFLAGS & SPI_IF_bm)); + return SPI->DATA; + } + + /** Sends a byte through the SPI interface, blocking until the transfer is complete. The response + * byte sent to from the attached SPI device is ignored. + * + * \param[in,out] SPI Pointer to the base of the SPI peripheral within the device. + * \param[in] Byte Byte to send through the SPI interface. + */ + static inline void SPI_SendByte(SPI_t* const SPI, + const uint8_t Byte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1); + static inline void SPI_SendByte(SPI_t* const SPI, + const uint8_t Byte) + { + SPI->DATA = Byte; + while (!(SPI->INTFLAGS & SPI_IF_bm)); + } + + /** Sends a dummy byte through the SPI interface, blocking until the transfer is complete. The response + * byte from the attached SPI device is returned. + * + * \param[in,out] SPI Pointer to the base of the SPI peripheral within the device. + * + * \return The response byte from the attached SPI device. + */ + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1) + static inline uint8_t SPI_ReceiveByte(SPI_t* const SPI) + { + SPI->DATA = 0; + while (!(SPI->INTFLAGS & SPI_IF_bm)); + return SPI->DATA; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Peripheral/AVRDX/SerialSPI_AVRDX.h b/LUFA/Drivers/Peripheral/AVRDX/SerialSPI_AVRDX.h new file mode 100644 index 000000000..a94352e72 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVRDX/SerialSPI_AVRDX.h @@ -0,0 +1,208 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Master SPI Mode Serial USART Peripheral Driver (AVR Dx) + * + * On-chip Master SPI mode USART driver for the AVR Dx microcontrollers. + * + * \note This file should not be included directly. It is automatically included as needed by the SPI Master + * Mode USART driver dispatch header located in LUFA/Drivers/Peripheral/Serial.h. + */ + +/** \ingroup Group_SerialSPI + * \defgroup Group_SerialSPI_AVRDX Master SPI Mode Serial USART Peripheral Driver (AVR Dx) + * + * \section Sec_SerialSPI_AVRDX_ModDescription Module Description + * On-chip serial USART driver for the AVR Dx microcontrollers. + * + * \note This file should not be included directly. It is automatically included as needed by the ADC driver + * dispatch header located in LUFA/Drivers/Peripheral/SerialSPI.h. + * + * \section Sec_SerialSPI_AVRDX_ExampleUsage Example Usage + * The following snippet is an example of how this module may be used within a typical + * application. + * + * \code + * // Initialize the Master SPI mode USART driver before first use, with 1Mbit baud + * SerialSPI_Init(&USARTD0, (USART_SPI_SCK_LEAD_RISING | USART_SPI_SAMPLE_LEADING | USART_SPI_ORDER_MSB_FIRST), 1000000); + * + * // Send several bytes, ignoring the returned data + * SerialSPI_SendByte(&USARTD0, 0x01); + * SerialSPI_SendByte(&USARTD0, 0x02); + * SerialSPI_SendByte(&USARTD0, 0x03); + * + * // Receive several bytes, sending a dummy 0x00 byte each time + * uint8_t Byte1 = SerialSPI_ReceiveByte(&USARTD); + * uint8_t Byte2 = SerialSPI_ReceiveByte(&USARTD); + * uint8_t Byte3 = SerialSPI_ReceiveByte(&USARTD); + * + * // Send a byte, and store the received byte from the same transaction + * uint8_t ResponseByte = SerialSPI_TransferByte(&USARTD0, 0xDC); + * \endcode + * + * @{ + */ + +#ifndef __SERIAL_SPI_AVRDX_H__ +#define __SERIAL_SPI_AVRDX_H__ + + /* Includes: */ + #include "../../../Common/Common.h" + + #include + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_SERIAL_SPI_H) + #error Do not include this file directly. Include LUFA/Drivers/Peripheral/Serial.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + #define SERIAL_SPI_BAUD(Baud) ((Baud < (F_CPU / 2)) ? ((F_CPU / (2 * Baud)) - 1) : 0) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** \name SPI SCK Polarity Configuration Masks */ + /**@{*/ + /** SPI clock polarity mask for \ref SerialSPI_Init(). Indicates that the SCK should lead on the rising edge. */ + #define USART_SPI_SCK_LEAD_RISING 0 + /**@}*/ + + /** \name SPI Sample Edge Configuration Masks */ + /**@{*/ + /** SPI data sample mode mask for \ref SerialSPI_Init(). Indicates that the data should sampled on the leading edge. */ + #define USART_SPI_SAMPLE_LEADING 0 + + /** SPI data sample mode mask for \ref SerialSPI_Init(). Indicates that the data should be sampled on the trailing edge. */ + #define USART_SPI_SAMPLE_TRAILING (1 << 1) + /**@}*/ + + /** \name SPI Data Ordering Configuration Masks */ + /**@{*/ + /** SPI data order mask for \ref SerialSPI_Init(). Indicates that data should be shifted out MSB first. */ + #define USART_SPI_ORDER_MSB_FIRST 0 + + /** SPI data order mask for \ref SerialSPI_Init(). Indicates that data should be shifted out LSB first. */ + #define USART_SPI_ORDER_LSB_FIRST (1 << 2) + /**@}*/ + + /* Inline Functions: */ + /** Initialize the USART module in Master SPI mode. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in] SPIOptions USART SPI Options, a mask consisting of one of each of the \c USART_SPI_SCK_*, + * \c USART_SPI_SAMPLE_* and \c USART_SPI_ORDER_* masks. + * \param[in] BaudRate SPI baud rate, in bits per second. + */ + static inline void SerialSPI_Init(USART_t* const USART, + const uint8_t SPIOptions, + const uint32_t BaudRate) ATTR_NON_NULL_PTR_ARG(1); + static inline void SerialSPI_Init(USART_t* const USART, + const uint8_t SPIOptions, + const uint32_t BaudRate) + { + USART->BAUD = SERIAL_SPI_BAUD(BaudRate); + USART->CTRLC = (USART_CMODE_MSPI_gc | SPIOptions); + USART->CTRLB = (USART_RXEN_bm | USART_TXEN_bm); + } + + /** Turns off the USART driver, disabling and returning used hardware to their default configuration. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + */ + ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) + static inline void SerialSPI_Disable(USART_t* const USART) + { + USART->CTRLA = 0; + USART->CTRLB = 0; + USART->CTRLC = 0; + } + + /** Sends and receives a byte through the USART SPI interface, blocking until the transfer is complete. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in] DataByte Byte to send through the USART SPI interface. + * + * \return Response byte from the attached SPI device. + */ + static inline uint8_t SerialSPI_TransferByte(USART_t* const USART, + const uint8_t DataByte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1); + static inline uint8_t SerialSPI_TransferByte(USART_t* const USART, + const uint8_t DataByte) + { + USART->TXDATAL = DataByte; + while (!(USART->STATUS & USART_TXCIF_bm)); + USART->STATUS = USART_TXCIF_bm; + return USART->RXDATAL; + } + + /** Sends a byte through the USART SPI interface, blocking until the transfer is complete. The response + * byte sent to from the attached SPI device is ignored. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in] DataByte Byte to send through the USART SPI interface. + */ + static inline void SerialSPI_SendByte(USART_t* const USART, + const uint8_t DataByte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1); + static inline void SerialSPI_SendByte(USART_t* const USART, + const uint8_t DataByte) + { + SerialSPI_TransferByte(USART, DataByte); + } + + /** Sends a dummy byte through the USART SPI interface, blocking until the transfer is complete. The response + * byte from the attached SPI device is returned. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * + * \return The response byte from the attached SPI device. + */ + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1) + static inline uint8_t SerialSPI_ReceiveByte(USART_t* const USART) + { + return SerialSPI_TransferByte(USART, 0); + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.c b/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.c new file mode 100644 index 000000000..09e3ebf0d --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.c @@ -0,0 +1,126 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_SERIAL_C +#include "../Serial.h" + +FILE USARTSerialStream; + +int Serial_putchar(char DataByte, + FILE *Stream) +{ + USART_t* USART = fdev_get_udata(Stream); + + Serial_SendByte(USART, DataByte); + return 0; +} + +int Serial_getchar(FILE *Stream) +{ + USART_t* USART = fdev_get_udata(Stream); + + if (!(Serial_IsCharReceived(USART))) + return _FDEV_EOF; + + return Serial_ReceiveByte(USART); +} + +int Serial_getchar_Blocking(FILE *Stream) +{ + USART_t* USART = fdev_get_udata(Stream); + + while (!(Serial_IsCharReceived(USART))); + return Serial_ReceiveByte(USART); +} + +void Serial_SendString_P(USART_t* const USART, + const char* FlashStringPtr) +{ + uint8_t CurrByte; + + while ((CurrByte = pgm_read_byte(FlashStringPtr)) != 0x00) + { + Serial_SendByte(USART, CurrByte); + FlashStringPtr++; + } +} + +void Serial_SendString(USART_t* const USART, + const char* StringPtr) +{ + uint8_t CurrByte; + + while ((CurrByte = *StringPtr) != 0x00) + { + Serial_SendByte(USART, CurrByte); + StringPtr++; + } +} + +void Serial_SendData(USART_t* const USART, + const void* Buffer, + uint16_t Length) +{ + uint8_t* CurrByte = (uint8_t*)Buffer; + + while (Length--) + Serial_SendByte(USART, *(CurrByte++)); +} + +void Serial_CreateStream(USART_t* USART, FILE* Stream) +{ + if (!(Stream)) + { + Stream = &USARTSerialStream; + stdin = Stream; + stdout = Stream; + } + + *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar, _FDEV_SETUP_RW); + fdev_set_udata(Stream, USART); +} + +void Serial_CreateBlockingStream(USART_t* USART, FILE* Stream) +{ + if (!(Stream)) + { + Stream = &USARTSerialStream; + stdin = Stream; + stdout = Stream; + } + + *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar_Blocking, _FDEV_SETUP_RW); + fdev_set_udata(Stream, USART); +} + +#endif diff --git a/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h b/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h new file mode 100644 index 000000000..b57c32840 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h @@ -0,0 +1,276 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Serial USART Peripheral Driver (AVR Dx) + * + * On-chip serial USART driver for the AVR Dx microcontrollers. + * + * \note This file should not be included directly. It is automatically included as needed by the USART driver + * dispatch header located in LUFA/Drivers/Peripheral/Serial.h. + */ + +/** \ingroup Group_Serial + * \defgroup Group_Serial_AVRDX Serial USART Peripheral Driver (AVR Dx) + * + * \section Sec_Serial_AVRDX_ModDescription Module Description + * On-chip serial USART driver for the AVR Dx microcontrollers. + * + * \note This file should not be included directly. It is automatically included as needed by the USART driver + * dispatch header located in LUFA/Drivers/Peripheral/Serial.h. + * + * \section Sec_Serial_AVRDX_ExampleUsage Example Usage + * The following snippet is an example of how this module may be used within a typical + * application. + * + * \code + * // Initialize the serial USART driver before first use, with 9600 baud (and no double-speed mode) + * Serial_Init(&USARTD0, 9600, false); + * + * // Send a string through the USART + * Serial_TxString(&USARTD0, "Test String\r\n"); + * + * // Receive a byte through the USART + * uint8_t DataByte = Serial_RxByte(&USARTD0); + * \endcode + * + * @{ + */ + +#ifndef __SERIAL_AVRDX_H__ +#define __SERIAL_AVRDX_H__ + + /* Includes: */ + #include "../../../Common/Common.h" + #include "../../Misc/TerminalCodes.h" + + #include + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_SERIAL_H) && !defined(__INCLUDE_FROM_SERIAL_C) + #error Do not include this file directly. Include LUFA/Drivers/Peripheral/Serial.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* External Variables: */ + extern FILE USARTSerialStream; + + /* Function Prototypes: */ + int Serial_putchar(char DataByte, + FILE *Stream); + int Serial_getchar(FILE *Stream); + int Serial_getchar_Blocking(FILE *Stream); + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Macro for calculating the baud value from a given baud rate. + * + * \param[in] Baud Target serial UART baud rate. + * + * \return Closest register value for the given UART frequency. + */ + #define SERIAL_BAUD(Baud) ((F_CPU * 64) / (16 * Baud)) + + + /* Function Prototypes: */ + /** Transmits a given string located in program space (FLASH) through the USART. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in] FlashStringPtr Pointer to a string located in program space. + */ + void Serial_SendString_P(USART_t* const USART, + const char* FlashStringPtr) ATTR_NON_NULL_PTR_ARG(1); + + /** Transmits a given string located in SRAM memory through the USART. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in] StringPtr Pointer to a string located in SRAM space. + */ + void Serial_SendString(USART_t* const USART, + const char* StringPtr) ATTR_NON_NULL_PTR_ARG(1); + + /** Transmits a given buffer located in SRAM memory through the USART. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in] Buffer Pointer to a buffer containing the data to send. + * \param[in] Length Length of the data to send, in bytes. + */ + void Serial_SendData(USART_t* const USART, + const void* Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** Creates a standard character stream from the USART so that it can be used with all the regular functions + * in the avr-libc \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. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed, if \c NULL, \c stdout + * and \c stdin will be configured to use the USART. + * + * \pre The USART must first be configured via a call to \ref Serial_Init() before the stream is used. + */ + void Serial_CreateStream(USART_t* USART, FILE* Stream); + + /** Identical to \ref Serial_CreateStream(), except that reads are blocking until the calling stream function terminates + * the transfer. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed, if \c NULL, \c stdout + * and \c stdin will be configured to use the USART. + * + * \pre The USART must first be configured via a call to \ref Serial_Init() before the stream is used. + */ + void Serial_CreateBlockingStream(USART_t* USART, FILE* Stream); + + /* Inline Functions: */ + /** Initializes the USART, ready for serial data transmission and reception. This initializes the interface to + * standard 8-bit, no parity, 1 stop bit settings suitable for most applications. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in] BaudRate Serial baud rate, in bits per second. This should be the target baud rate regardless of + * the \c DoubleSpeed parameter's value. + * \param[in] DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate. + */ + static inline void Serial_Init(USART_t* const USART, + const uint32_t BaudRate, + const bool DoubleSpeed) ATTR_NON_NULL_PTR_ARG(1); + static inline void Serial_Init(USART_t* const USART, + const uint32_t BaudRate, + const bool DoubleSpeed) + { + USART->BAUD = SERIAL_BAUD(BaudRate); + USART->CTRLC = (USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc); + USART->CTRLB = (USART_RXEN_bm | USART_TXEN_bm | (DoubleSpeed ? USART_RXMODE_CLK2X_gc : USART_RXMODE_NORMAL_gc)); + } + + /** Turns off the USART driver, disabling and returning used hardware to their default configuration. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + */ + ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) + static inline void Serial_Disable(USART_t* const USART) + { + USART->CTRLA = 0; + USART->CTRLB = 0; + USART->CTRLC = 0; + } + + /** Indicates whether a character has been received through the USART. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * + * \return Boolean \c true if a character has been received, \c false otherwise. + */ + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1) + static inline bool Serial_IsCharReceived(USART_t* const USART) + { + return ((USART->STATUS & USART_RXCIF_bm) ? true : false); + } + + /** Indicates whether there is hardware buffer space for a new transmit on the USART. This + * function can be used to determine if a call to \ref Serial_SendByte() will block in advance. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * + * \return Boolean \c true if a character can be queued for transmission immediately, \c false otherwise. + */ + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1) + static inline bool Serial_IsSendReady(USART_t* const USART) + { + return (USART->STATUS & USART_DREIF_bm) ? true : false; + } + + /** Indicates whether the hardware USART transmit buffer is completely empty, indicating all + * pending transmissions have completed. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * + * \return Boolean \c true if no characters are buffered for transmission, \c false otherwise. + */ + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1) + static inline bool Serial_IsSendComplete(USART_t* const USART) + { + return (USART->STATUS & USART_TXCIF_bm) ? true : false; + } + + /** Transmits a given byte through the USART. + * + * \note If no buffer space is available in the hardware USART, this function will block. To check if + * space is available before calling this function, see \ref Serial_IsSendReady(). + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * \param[in] DataByte Byte to transmit through the USART. + */ + static inline void Serial_SendByte(USART_t* const USART, + const char DataByte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1); + static inline void Serial_SendByte(USART_t* const USART, + const char DataByte) + { + while (!(Serial_IsSendReady(USART))); + USART->TXDATAL = DataByte; + } + + /** Receives the next byte from the USART. + * + * \param[in,out] USART Pointer to the base of the USART peripheral within the device. + * + * \return Next byte received from the USART, or a negative value if no byte has been received. + */ + ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) + static inline int16_t Serial_ReceiveByte(USART_t* const USART) + { + if (!(Serial_IsCharReceived(USART))) + return -1; + + USART->STATUS = USART_RXCIF_bm; + return USART->RXDATAL; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.c b/LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.c new file mode 100644 index 000000000..4618213dc --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.c @@ -0,0 +1,185 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_TWI_C +#include "../TWI.h" + +uint8_t TWI_StartTransmission(TWI_t* const TWI, + const uint8_t SlaveAddress, + const uint8_t TimeoutMS) +{ + uint16_t TimeoutRemaining; + + TWI->MADDR = SlaveAddress; + + TimeoutRemaining = (TimeoutMS * 100); + while (TimeoutRemaining) + { + uint8_t status = TWI->MSTATUS; + + if ((status & (TWI_WIF_bm | TWI_ARBLOST_bm)) == (TWI_WIF_bm | TWI_ARBLOST_bm)) + { + TWI->MADDR = SlaveAddress; + } + else if ((status & (TWI_WIF_bm | TWI_RXACK_bm)) == (TWI_WIF_bm | TWI_RXACK_bm)) + { + TWI_StopTransmission(TWI); + return TWI_ERROR_SlaveResponseTimeout; + } + else if (status & (TWI_WIF_bm | TWI_RIF_bm)) + { + return TWI_ERROR_NoError; + } + + _delay_us(10); + TimeoutRemaining--; + } + + if (!(TimeoutRemaining)) { + if (TWI->MSTATUS & TWI_CLKHOLD_bm) { + TWI_StopTransmission(TWI); + } + } + + return TWI_ERROR_BusCaptureTimeout; +} + +bool TWI_SendByte(TWI_t* const TWI, + const uint8_t Byte) +{ + TWI->MDATA = Byte; + + while (!(TWI->MSTATUS & TWI_WIF_bm)); + + return (TWI->MSTATUS & TWI_WIF_bm) && !(TWI->MSTATUS & TWI_RXACK_bm); +} + +bool TWI_ReceiveByte(TWI_t* const TWI, + uint8_t* const Byte, + const bool LastByte) +{ + if ((TWI->MSTATUS & (TWI_BUSERR_bm | TWI_ARBLOST_bm)) == (TWI_BUSERR_bm | TWI_ARBLOST_bm)) { + return false; + } + + while (!(TWI->MSTATUS & TWI_RIF_bm)); + + *Byte = TWI->MDATA; + + if (LastByte) + TWI->MCTRLB = TWI_ACKACT_bm | TWI_MCMD_STOP_gc; + else + TWI->MCTRLB = TWI_MCMD_RECVTRANS_gc; + + return true; +} + +uint8_t TWI_ReadPacket(TWI_t* const TWI, + const uint8_t SlaveAddress, + const uint8_t TimeoutMS, + const uint8_t* InternalAddress, + uint8_t InternalAddressLen, + uint8_t* Buffer, + uint16_t Length) +{ + uint8_t ErrorCode; + + if ((ErrorCode = TWI_StartTransmission(TWI, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_WRITE, + TimeoutMS)) == TWI_ERROR_NoError) + { + while (InternalAddressLen--) + { + if (!(TWI_SendByte(TWI, *(InternalAddress++)))) + { + ErrorCode = TWI_ERROR_SlaveNAK; + break; + } + } + + if ((ErrorCode = TWI_StartTransmission(TWI, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_READ, + TimeoutMS)) == TWI_ERROR_NoError) + { + while (Length--) + { + if (!(TWI_ReceiveByte(TWI, Buffer++, (Length == 0)))) + { + ErrorCode = TWI_ERROR_SlaveNAK; + break; + } + } + } + + TWI_StopTransmission(TWI); + } + + return ErrorCode; +} + +uint8_t TWI_WritePacket(TWI_t* const TWI, + const uint8_t SlaveAddress, + const uint8_t TimeoutMS, + const uint8_t* InternalAddress, + uint8_t InternalAddressLen, + const uint8_t* Buffer, + uint16_t Length) +{ + uint8_t ErrorCode; + + if ((ErrorCode = TWI_StartTransmission(TWI, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_WRITE, + TimeoutMS)) == TWI_ERROR_NoError) + { + while (InternalAddressLen--) + { + if (!(TWI_SendByte(TWI, *(InternalAddress++)))) + { + ErrorCode = TWI_ERROR_SlaveNAK; + break; + } + } + + while (Length--) + { + if (!(TWI_SendByte(TWI, *(Buffer++)))) + { + ErrorCode = TWI_ERROR_SlaveNAK; + break; + } + } + + TWI_StopTransmission(TWI); + } + + return ErrorCode; +} + +#endif diff --git a/LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.h b/LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.h new file mode 100644 index 000000000..d2c60e529 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.h @@ -0,0 +1,301 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief TWI Peripheral Driver (AVR Dx) + * + * On-chip TWI driver for the AVR Dx Family of AVR microcontrollers. + * + * \note This file should not be included directly. It is automatically included as needed by the TWI driver + * dispatch header located in LUFA/Drivers/Peripheral/TWI.h. + */ + +/** \ingroup Group_TWI + * \defgroup Group_TWI_AVRDX TWI Peripheral Driver (AVR Dx) + * + * \section Sec_TWI_AVRDX_ModDescription Module Description + * Master mode TWI driver for the 8-bit AVR microcontrollers which contain a hardware TWI module. + * + * \note This file should not be included directly. It is automatically included as needed by the TWI driver + * dispatch header located in LUFA/Drivers/Peripheral/TWI.h. + * + * \section Sec_TWI_AVRDX_ExampleUsage Example Usage + * The following snippet is an example of how this module may be used within a typical + * application. + * + * Low Level API Example: + * \code + * // Initialize the TWI driver before first use at 200KHz + * TWI_Init(&TWIC, TWI_BAUD_FROM_FREQ(200000)); + * + * // Start a write session to device at device address 0xA0, internal address 0xDC with a 10ms timeout + * if (TWI_StartTransmission(&TWIC, 0xA0 | TWI_ADDRESS_WRITE, 10) == TWI_ERROR_NoError) + * { + * TWI_SendByte(&TWIC, 0xDC); + * + * TWI_SendByte(&TWIC, 0x01); + * TWI_SendByte(&TWIC, 0x02); + * TWI_SendByte(&TWIC, 0x03); + * + * // Must stop transmission afterwards to release the bus + * TWI_StopTransmission(&TWIC); + * } + * + * // Start a read session to device at address 0xA0, internal address 0xDC with a 10ms timeout + * if (TWI_StartTransmission(&TWIC, 0xA0 | TWI_ADDRESS_WRITE, 10) == TWI_ERROR_NoError) + * { + * TWI_SendByte(&TWIC, 0xDC); + * TWI_StopTransmission(&TWIC); + * + * if (TWI_StartTransmission(&TWIC, 0xA0 | TWI_ADDRESS_READ, 10) == TWI_ERROR_NoError) + * { + * uint8_t Byte1, Byte2, Byte3; + * + * // Read three bytes, acknowledge after the third byte is received + * TWI_ReceiveByte(&TWIC, &Byte1, false); + * TWI_ReceiveByte(&TWIC, &Byte2, false); + * TWI_ReceiveByte(&TWIC, &Byte3, true); + * + * // Must stop transmission afterwards to release the bus + * TWI_StopTransmission(&TWIC); + * } + * } + * \endcode + * + * High Level API Example: + * \code + * // Initialize the TWI driver before first use at 200KHz + * TWI_Init(&TWIC, TWI_BAUD_FROM_FREQ(200000)); + * + * // Start a write session to device at device address 0xA0, internal address 0xDC with a 10ms timeout + * uint8_t InternalWriteAddress = 0xDC; + * uint8_t WritePacket[3] = {0x01, 0x02, 0x03}; + * + * TWI_WritePacket(&TWIC, 0xA0, 10, &InternalWriteAddress, sizeof(InternalWriteAddress), + * &WritePacket, sizeof(WritePacket); + * + * // Start a read session to device at address 0xA0, internal address 0xDC with a 10ms timeout + * uint8_t InternalReadAddress = 0xDC; + * uint8_t ReadPacket[3]; + * + * TWI_ReadPacket(&TWIC, 0xA0, 10, &InternalReadAddress, sizeof(InternalReadAddress), + * &ReadPacket, sizeof(ReadPacket); + * \endcode + * + * @{ + */ + +#ifndef __TWI_AVRDX_H__ +#define __TWI_AVRDX_H__ + + /* Includes: */ + #include "../../../Common/Common.h" + + #include + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_TWI_H) && !defined(__INCLUDE_FROM_TWI_C) + #error Do not include this file directly. Include LUFA/Drivers/Peripheral/TWI.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** TWI slave device address mask for a read session. Mask with a slave device base address to obtain + * the correct TWI bus address for the slave device when reading data from it. + */ + #define TWI_ADDRESS_READ 0x01 + + /** TWI slave device address mask for a write session. Mask with a slave device base address to obtain + * the correct TWI bus address for the slave device when writing data to it. + */ + #define TWI_ADDRESS_WRITE 0x00 + + /** Mask to retrieve the base address for a TWI device, which can then be ORed with \ref TWI_ADDRESS_READ + * or \ref TWI_ADDRESS_WRITE to obtain the device's read and write address respectively. + */ + #define TWI_DEVICE_ADDRESS_MASK 0xFE + + /** Calculates the length of each bit on the TWI bus for a given target frequency. This may be used with + * the \ref TWI_Init() function to convert a bus frequency to a number of clocks for the \c BitLength + * parameter. + * + * \param[in] Frequency Desired TWI bus frequency in Hz. + * + * \return Bit length in clocks for the given TWI bus frequency at the given prescaler value. + */ + #define TWI_BAUD_FROM_FREQ(Frequency) ((F_CPU / (2 * Frequency)) - 5) + + /* Enums: */ + /** Enum for the possible return codes of the TWI transfer start routine and other dependant TWI functions. */ + enum TWI_ErrorCodes_t + { + TWI_ERROR_NoError = 0, /**< Indicates that the command completed successfully. */ + TWI_ERROR_BusFault = 1, /**< A TWI bus fault occurred while attempting to capture the bus. */ + TWI_ERROR_BusCaptureTimeout = 2, /**< A timeout occurred whilst waiting for the bus to be ready. */ + TWI_ERROR_SlaveResponseTimeout = 3, /**< No ACK received at the nominated slave address within the timeout period. */ + TWI_ERROR_SlaveNotReady = 4, /**< Slave NAKed the TWI bus START condition. */ + TWI_ERROR_SlaveNAK = 5, /**< Slave NAKed whilst attempting to send data to the device. */ + }; + + /* Inline Functions: */ + /** Initializes the TWI hardware into master mode, ready for data transmission and reception. This must be + * before any other TWI operations. + * + * The generated SCL frequency will be according to the formula
F_CPU / (2 * (5 + (BAUD)))
. + * + * \attention The value of the \c BitLength parameter should not be set below 10 or invalid bus conditions may + * occur, as indicated in the AVR Dx microcontroller datasheet. + * + * \param[in] TWI Pointer to the base of the TWI peripheral within the device. + * \param[in] Baud Value of the BAUD register of the TWI Master. + */ + static inline void TWI_Init(TWI_t* const TWI, + const uint8_t Baud) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1); + static inline void TWI_Init(TWI_t* const TWI, + const uint8_t Baud) + { + TWI->MBAUD = Baud; + TWI->MCTRLA = TWI_ENABLE_bm; + TWI->MCTRLB = 0; + TWI->MSTATUS = TWI_BUSSTATE_IDLE_gc; + } + + /** Turns off the TWI driver hardware. If this is called, any further TWI operations will require a call to + * \ref TWI_Init() before the TWI can be used again. + * + * \param[in] TWI Pointer to the base of the TWI peripheral within the device. + */ + ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) + static inline void TWI_Disable(TWI_t* const TWI) + { + TWI->MCTRLA &= ~TWI_ENABLE_bm; + } + + /** Sends a TWI STOP onto the TWI bus, terminating communication with the currently addressed device. + * + * \param[in] TWI Pointer to the base of the TWI peripheral within the device. + */ + ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) + static inline void TWI_StopTransmission(TWI_t* const TWI) + { + TWI->MCTRLB = TWI_ACKACT_bm | TWI_MCMD_STOP_gc; + } + + /* Function Prototypes: */ + /** Begins a master mode TWI bus communication with the given slave device address. + * + * \param[in] TWI Pointer to the base of the TWI peripheral within the device. + * \param[in] SlaveAddress Address of the slave TWI device to communicate with. + * \param[in] TimeoutMS Timeout period within which the slave must respond, in milliseconds. + * + * \return A value from the \ref TWI_ErrorCodes_t enum. + */ + uint8_t TWI_StartTransmission(TWI_t* const TWI, + const uint8_t SlaveAddress, + const uint8_t TimeoutMS) ATTR_NON_NULL_PTR_ARG(1); + + /** Sends a byte to the currently addressed device on the TWI bus. + * + * \param[in] TWI Pointer to the base of the TWI peripheral within the device. + * \param[in] Byte Byte to send to the currently addressed device + * + * \return Boolean \c true if the recipient ACKed the byte, \c false otherwise + */ + bool TWI_SendByte(TWI_t* const TWI, + const uint8_t Byte) ATTR_NON_NULL_PTR_ARG(1); + + /** Receives a byte from the currently addressed device on the TWI bus. + * + * \param[in] TWI Pointer to the base of the TWI peripheral within the device. + * \param[in] Byte Location where the read byte is to be stored. + * \param[in] LastByte Indicates if the byte should be ACKed if false, NAKed if true. + * + * \return Boolean \c true if the byte reception successfully completed, \c false otherwise. + */ + bool TWI_ReceiveByte(TWI_t* const TWI, + uint8_t* const Byte, + const bool LastByte) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2); + + /** High level function to perform a complete packet transfer over the TWI bus to the specified + * device. + * + * \param[in] TWI Pointer to the base of the TWI peripheral within the device. + * \param[in] SlaveAddress Base address of the TWI slave device to communicate with. + * \param[in] TimeoutMS Timeout for bus capture and slave START ACK, in milliseconds. + * \param[in] InternalAddress Pointer to a location where the internal slave read start address is stored. + * \param[in] InternalAddressLen Size of the internal device address, in bytes. + * \param[in] Buffer Pointer to a buffer where the read packet data is to be stored. + * \param[in] Length Size of the packet to read, in bytes. + * + * \return A value from the \ref TWI_ErrorCodes_t enum. + */ + uint8_t TWI_ReadPacket(TWI_t* const TWI, + const uint8_t SlaveAddress, + const uint8_t TimeoutMS, + const uint8_t* InternalAddress, + uint8_t InternalAddressLen, + uint8_t* Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(4); + + /** High level function to perform a complete packet transfer over the TWI bus from the specified + * device. + * + * \param[in] TWI Pointer to the base of the TWI peripheral within the device. + * \param[in] SlaveAddress Base address of the TWI slave device to communicate with + * \param[in] TimeoutMS Timeout for bus capture and slave START ACK, in milliseconds + * \param[in] InternalAddress Pointer to a location where the internal slave write start address is stored + * \param[in] InternalAddressLen Size of the internal device address, in bytes + * \param[in] Buffer Pointer to a buffer where the packet data to send is stored + * \param[in] Length Size of the packet to send, in bytes + * + * \return A value from the \ref TWI_ErrorCodes_t enum. + */ + uint8_t TWI_WritePacket(TWI_t* const TWI, + const uint8_t SlaveAddress, + const uint8_t TimeoutMS, + const uint8_t* InternalAddress, + uint8_t InternalAddressLen, + const uint8_t* Buffer, + uint16_t Length) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(4); + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h index 3c1513d10..f0c560065 100644 --- a/LUFA/Drivers/Peripheral/SPI.h +++ b/LUFA/Drivers/Peripheral/SPI.h @@ -68,6 +68,8 @@ #include "AVR8/SPI_AVR8.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/SPI_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/SPI_AVRDX.h" #else #error The SPI peripheral driver is not currently available for your selected architecture. #endif diff --git a/LUFA/Drivers/Peripheral/Serial.h b/LUFA/Drivers/Peripheral/Serial.h index 7c8a944e1..27c01cedc 100644 --- a/LUFA/Drivers/Peripheral/Serial.h +++ b/LUFA/Drivers/Peripheral/Serial.h @@ -68,6 +68,8 @@ #include "AVR8/Serial_AVR8.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/Serial_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/Serial_AVRDX.h" #else #error The Serial peripheral driver is not currently available for your selected architecture. #endif diff --git a/LUFA/Drivers/Peripheral/SerialSPI.h b/LUFA/Drivers/Peripheral/SerialSPI.h index b74529f70..aa9b1bf5f 100644 --- a/LUFA/Drivers/Peripheral/SerialSPI.h +++ b/LUFA/Drivers/Peripheral/SerialSPI.h @@ -68,6 +68,8 @@ #include "AVR8/SerialSPI_AVR8.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/SerialSPI_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/SerialSPI_AVRDX.h" #else #error The Serial SPI Master Mode peripheral driver is not currently available for your selected architecture. #endif diff --git a/LUFA/Drivers/Peripheral/TWI.h b/LUFA/Drivers/Peripheral/TWI.h index c7e20cfda..72f53b90e 100644 --- a/LUFA/Drivers/Peripheral/TWI.h +++ b/LUFA/Drivers/Peripheral/TWI.h @@ -68,6 +68,8 @@ #include "AVR8/TWI_AVR8.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/TWI_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/TWI_AVRDX.h" #else #error The TWI peripheral driver is not currently available for your selected architecture. #endif diff --git a/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.c new file mode 100644 index 000000000..ea40ff823 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.c @@ -0,0 +1,49 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "../Device.h" + +void USB_Device_SendRemoteWakeup(void) +{ + USB0.CTRLB |= USB_URESUME_bm; +} + +#endif + +#endif + diff --git a/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h new file mode 100644 index 000000000..e593ef694 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h @@ -0,0 +1,232 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief USB Device definitions for the AVR Dx microcontrollers. + * \copydetails Group_Device_AVRDX + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_Device + * \defgroup Group_Device_AVRDX Device Management (AVR Dx) + * \brief USB Device definitions for the AVR Dx microcontrollers. + * + * Architecture specific USB Device definitions for the Atmel AVR Dx microcontrollers. + * + * @{ + */ + +#ifndef __USBDEVICE_AVRDX_H__ +#define __USBDEVICE_AVRDX_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBController.h" + #include "../StdDescriptors.h" + #include "../USBInterrupt.h" + #include "../Endpoint.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + #if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)) + #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. + #endif + + #if (defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)) + #error USE_FLASH_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. + #endif + + #if (defined(USE_FLASH_DESCRIPTORS) && defined(USE_RAM_DESCRIPTORS)) + #error USE_FLASH_DESCRIPTORS and USE_RAM_DESCRIPTORS are mutually exclusive. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #if (!defined(NO_INTERNAL_SERIAL) || defined(__DOXYGEN__)) + /** String descriptor index for the device's unique serial number string descriptor within the device. + * This unique serial number is used by the host to associate resources to the device (such as drivers or COM port + * number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain + * a unique serial number internally, and setting the device descriptors serial number string index to this value + * will cause it to use the internal serial number. + * + * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial + * number for the device. + */ + #ifndef USE_INTERNAL_SERIAL + #define USE_INTERNAL_SERIAL 0xDC + #endif + + /** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller + * model. + */ + #define INTERNAL_SERIAL_LENGTH_BITS (8 * (1 + (offsetof(SIGROW_t, SERNUM15) - offsetof(SIGROW_t, SERNUM0)))) + + /** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller + * model. + */ + #define INTERNAL_SERIAL_START_ADDRESS &SIGROW.SERNUM0 + #else + #undef USE_INTERNAL_SERIAL + #define USE_INTERNAL_SERIAL NO_DESCRIPTOR + + #define INTERNAL_SERIAL_LENGTH_BITS 0 + #define INTERNAL_SERIAL_START_ADDRESS 0 + #endif + + /* Function Prototypes: */ + /** Sends a Remote Wakeup request to the host. This signals to the host that the device should + * be taken out of suspended mode, and communications should resume. + * + * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the + * host computer when the host has suspended all USB devices to enter a low power state. + * + * \note This function should only be used if the device has indicated to the host that it + * supports the Remote Wakeup feature in the device descriptors, and should only be + * issued if the host is currently allowing remote wakeup events from the device (i.e., + * the \ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP + * compile time option is used, this function is unavailable. + * \n\n + * + * \note The USB clock must be running for this function to operate. If the stack is initialized with + * the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running + * before attempting to call this function. + * + * \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors. + */ + void USB_Device_SendRemoteWakeup(void); + + /* Inline Functions: */ + /** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host) + * the frame number is incremented by one. + * + * \return Current USB frame number from the USB controller. + */ + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT + static inline uint16_t USB_Device_GetFrameNumber(void) + { + return ((USB_EndpointTable_t*)USB0.EPPTR)->FrameNum; + } + + #if !defined(NO_SOF_EVENTS) + /** Enables the device mode Start Of Frame events. When enabled, this causes the + * \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus, + * at the start of each USB frame when enumerated in device mode. + * + * \note This function is not available when the \c NO_SOF_EVENTS compile time token is defined. + */ + ATTR_ALWAYS_INLINE + static inline void USB_Device_EnableSOFEvents(void) + { + USB0.INTCTRLA |= USB_SOF_bm; + } + + /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the + * \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode. + * + * \note This function is not available when the \c NO_SOF_EVENTS compile time token is defined. + */ + ATTR_ALWAYS_INLINE + static inline void USB_Device_DisableSOFEvents(void) + { + USB0.INTCTRLA &= ~USB_SOF_bm; + } + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Inline Functions: */ + ATTR_ALWAYS_INLINE + static inline void USB_Device_SetDeviceAddress(const uint8_t Address) + { + (void)Address; + + /* Use USB_Device_EnableDeviceAddress for AVR Dx */ + } + + ATTR_ALWAYS_INLINE + static inline void USB_Device_EnableDeviceAddress(const uint8_t Address) + { + USB0.ADDR = Address; + } + + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT + static inline bool USB_Device_IsAddressSet(void) + { + return ((USB0.ADDR != 0) ? true : false); + } + + ATTR_NON_NULL_PTR_ARG(1) + static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString) + { + uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); + GlobalInterruptDisable(); + + uint8_t* SigReadAddress = (uint8_t *) INTERNAL_SERIAL_START_ADDRESS; + + for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++) + { + uint8_t SerialByte = *SigReadAddress; + + if (SerialCharNum & 0x01) + { + SerialByte >>= 4; + SigReadAddress++; + } + + SerialByte &= 0x0F; + + UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ? + (('A' - 10) + SerialByte) : ('0' + SerialByte)); + } + + SetGlobalInterruptMask(CurrentGlobalInt); + } + + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.c new file mode 100644 index 000000000..4d6d1a5d8 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.c @@ -0,0 +1,265 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "EndpointStream_AVRDX.h" + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = BytesProcessed ? *BytesProcessed : 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + while (BytesInTransfer < 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(); + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = BytesProcessed ? *BytesProcessed : 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + while (BytesInTransfer < 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); + 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 + +#endif + +#endif diff --git a/LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.h new file mode 100644 index 000000000..f82c162e4 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.h @@ -0,0 +1,658 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Endpoint data stream transmission and reception management for the AVR Dx microcontrollers. + * \copydetails Group_EndpointStreamRW_AVRDX + * + * \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_AVRDX Read/Write of Multi-Byte Streams (AVR Dx) + * \brief Endpoint data stream transmission and reception management for the Atmel AVR Dx architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + * + * @{ + */ + +#ifndef __ENDPOINT_STREAM_AVRDX_H__ +#define __ENDPOINT_STREAM_AVRDX_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 status OUT packet + * to finalize the transfer's status stage via the \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 status OUT packet + * to finalize the transfer's status stage via the \ref Endpoint_ClearOUT() macro. + * + * \note This function automatically sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 + * status IN packet to finalize the transfer's status stage via the \ref Endpoint_ClearIN() macro. + * + * \note This function automatically sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 + * status IN packet to finalize the transfer's status stage via the \ref Endpoint_ClearIN() macro. + * + * \note This function automatically sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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 sends the last packet in the data stage of the transaction; when the + * function returns, the user is responsible for clearing the status stage of the transaction. + * Note that the status stage packet is sent or received in the opposite direction of the data flow. + * \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/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c new file mode 100644 index 000000000..bc2c1a323 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c @@ -0,0 +1,271 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "../Endpoint.h" + +#if !defined(FIXED_CONTROL_ENDPOINT_SIZE) +uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; +#endif + +Endpoint_FIFOPair_t USB_Endpoint_FIFOs[ENDPOINT_TOTAL_ENDPOINTS]; + +volatile uint8_t USB_Endpoint_SelectedEndpoint; +volatile USB_EP_t* USB_Endpoint_SelectedHandle; +volatile Endpoint_FIFO_t* USB_Endpoint_SelectedFIFO; + +bool Endpoint_IsINReady(void) +{ + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); + + return ((Endpoint_GetStatus() & USB_BUSNAK_bm) ? true : false); +} + +bool Endpoint_IsOUTReceived(void) +{ + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); + + if (Endpoint_GetStatus() & USB_TRNCOMPL_bm) + { + USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; + return true; + } + + return false; +} + +bool Endpoint_IsSETUPReceived(void) +{ + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); + + if (Endpoint_GetStatus() & USB_EPSETUP_bm) + { + USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; + return true; + } + + return false; +} + +void Endpoint_ClearSETUP(void) +{ + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); + Endpoint_ClearStatus(USB_EPSETUP_bm | USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_UNFOVF_bm); + Endpoint_SetStatus(USB_TOGGLE_bm); + USB_Endpoint_SelectedFIFO->Position = 0; + + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); + Endpoint_ClearStatus(USB_EPSETUP_bm); + Endpoint_SetStatus(USB_TOGGLE_bm); + USB_Endpoint_SelectedFIFO->Position = 0; +} + +void Endpoint_ClearIN(void) +{ + USB_Endpoint_SelectedHandle->CNT = USB_Endpoint_SelectedFIFO->Position; + Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_UNFOVF_bm); + USB_Endpoint_SelectedFIFO->Position = 0; +} + +void Endpoint_ClearOUT(void) +{ + Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_UNFOVF_bm); + USB_Endpoint_SelectedFIFO->Position = 0; +} + +void Endpoint_StallTransaction(void) +{ + USB_Endpoint_SelectedHandle->CTRL |= USB_DOSTALL_bm; + + if ((USB_Endpoint_SelectedHandle->CTRL & USB_TYPE_gm) == USB_TYPE_CONTROL_gc) + { + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint ^ ENDPOINT_DIR_IN); + USB_Endpoint_SelectedHandle->CTRL |= USB_DOSTALL_bm; + } +} + +uint8_t Endpoint_Read_8(void) +{ + return USB_Endpoint_SelectedFIFO->Data[USB_Endpoint_SelectedFIFO->Position++]; +} + +void Endpoint_Write_8(const uint8_t Data) +{ + USB_Endpoint_SelectedFIFO->Data[USB_Endpoint_SelectedFIFO->Position++] = Data; +} + +void Endpoint_SelectEndpoint(const uint8_t Address) +{ + uint8_t EndpointNumber = (Address & ENDPOINT_EPNUM_MASK); + + USB_Endpoint_SelectedEndpoint = Address; + + Endpoint_FIFOPair_t* EndpointFIFOPair = &USB_Endpoint_FIFOs[EndpointNumber]; + USB_EndpointTable_t* EndpointTable = (USB_EndpointTable_t*)USB0.EPPTR; + + if (Address & ENDPOINT_DIR_IN) + { + USB_Endpoint_SelectedFIFO = &EndpointFIFOPair->IN; + USB_Endpoint_SelectedHandle = &EndpointTable->Endpoints[EndpointNumber].IN; + } + else + { + USB_Endpoint_SelectedFIFO = &EndpointFIFOPair->OUT; + USB_Endpoint_SelectedHandle = &EndpointTable->Endpoints[EndpointNumber].OUT; + } +} + +bool Endpoint_ConfigureEndpointTable(const USB_Endpoint_Table_t* const Table, + const uint8_t Entries) +{ + for (uint8_t i = 0; i < Entries; i++) + { + if (!(Table[i].Address)) + continue; + + if (!(Endpoint_ConfigureEndpoint(Table[i].Address, Table[i].Type, Table[i].Size, Table[i].Banks))) + { + return false; + } + } + + return true; +} + +bool Endpoint_ConfigureEndpoint_PRV(const uint8_t Address, + const uint8_t Config, + const uint8_t Size) +{ + Endpoint_SelectEndpoint(Address); + + USB_Endpoint_SelectedHandle->CTRL = 0; + Endpoint_ClearStatus(0xff); + if(Address & ENDPOINT_DIR_IN) + Endpoint_SetStatus(USB_BUSNAK_bm); + USB_Endpoint_SelectedHandle->CTRL = Config; + USB_Endpoint_SelectedHandle->CNT = 0; + USB_Endpoint_SelectedHandle->DATAPTR = (intptr_t)USB_Endpoint_SelectedFIFO->Data; + + USB_Endpoint_SelectedFIFO->Length = (Address & ENDPOINT_DIR_IN) ? Size : 0; + USB_Endpoint_SelectedFIFO->Position = 0; + + return true; +} + +void Endpoint_ClearEndpoints(void) +{ + for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++) + { + ((USB_EndpointTable_t*)USB0.EPPTR)->Endpoints[EPNum].IN.CTRL = 0; + ((USB_EndpointTable_t*)USB0.EPPTR)->Endpoints[EPNum].OUT.CTRL = 0; + } +} + +void Endpoint_ClearStatusStage(void) +{ + if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST) + { + while (!(Endpoint_IsOUTReceived())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } + + Endpoint_ClearOUT(); + } + else + { + while (!(Endpoint_IsINReady())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } + + Endpoint_ClearIN(); + } +} + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_WaitUntilReady(void) +{ + #if (USB_STREAM_TIMEOUT_MS < 0xFF) + uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + #else + uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + #endif + + uint16_t PreviousFrameNumber = USB_Device_GetFrameNumber(); + + for (;;) + { + if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN) + { + if (Endpoint_IsINReady()) + return ENDPOINT_READYWAIT_NoError; + } + else + { + if (Endpoint_IsOUTReceived()) + return ENDPOINT_READYWAIT_NoError; + } + + uint8_t USB_DeviceState_LCL = USB_DeviceState; + + if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) + return ENDPOINT_READYWAIT_DeviceDisconnected; + else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) + return ENDPOINT_READYWAIT_BusSuspended; + else if (Endpoint_IsStalled()) + return ENDPOINT_READYWAIT_EndpointStalled; + + uint16_t CurrentFrameNumber = USB_Device_GetFrameNumber(); + + if (CurrentFrameNumber != PreviousFrameNumber) + { + PreviousFrameNumber = CurrentFrameNumber; + + if (!(TimeoutMSRem--)) + return ENDPOINT_READYWAIT_Timeout; + } + } +} +#endif + +#endif + +#endif + diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h new file mode 100644 index 000000000..3185d3cb1 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h @@ -0,0 +1,724 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief USB Endpoint definitions for the AVR Dx microcontrollers. + * \copydetails Group_EndpointManagement_AVRDX + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointRW + * \defgroup Group_EndpointRW_AVRDX Endpoint Data Reading and Writing (AVR Dx) + * \brief Endpoint data read/write definitions for the Atmel AVR Dx architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints. + */ + +/** \ingroup Group_EndpointPrimitiveRW + * \defgroup Group_EndpointPrimitiveRW_AVRDX Read/Write of Primitive Data Types (AVR Dx) + * \brief Endpoint primitive read/write definitions for the Atmel AVR Dx architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of primitive data types + * from and to endpoints. + */ + +/** \ingroup Group_EndpointPacketManagement + * \defgroup Group_EndpointPacketManagement_AVRDX Endpoint Packet Management (AVR Dx) + * \brief Endpoint packet management definitions for the Atmel AVR Dx architecture. + * + * Functions, macros, variables, enums and types related to packet management of endpoints. + */ + +/** \ingroup Group_EndpointManagement + * \defgroup Group_EndpointManagement_AVRDX Endpoint Management (AVR Dx) + * \brief Endpoint management definitions for the Atmel AVR Dx architecture. + * + * Functions, macros and enums related to endpoint management when in USB Device mode. This + * module contains the endpoint management macros, as well as endpoint interrupt and data + * send/receive functions for various data types. + * + * @{ + */ + +#ifndef __ENDPOINT_AVRDX_H__ +#define __ENDPOINT_AVRDX_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBTask.h" + #include "../USBInterrupt.h" + #include "../USBController.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #if (!defined(MAX_ENDPOINT_INDEX) && !defined(CONTROL_ONLY_DEVICE)) || defined(__DOXYGEN__) + /** Total number of endpoints (including the default control endpoint at address 0) which may + * be used in the device. Different USB AVR models support different amounts of endpoints, + * this value reflects the maximum number of endpoints for the currently selected AVR model. + */ + #define ENDPOINT_TOTAL_ENDPOINTS 16 + #else + #if defined(CONTROL_ONLY_DEVICE) + #define ENDPOINT_TOTAL_ENDPOINTS 1 + #else + #define ENDPOINT_TOTAL_ENDPOINTS (MAX_ENDPOINT_INDEX + 1) + #endif + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Type Defines: */ + typedef struct + { + uint8_t Data[64]; + + uint8_t Length; + uint8_t Position; + } Endpoint_FIFO_t; + + typedef struct + { + Endpoint_FIFO_t OUT; + Endpoint_FIFO_t IN; + } Endpoint_FIFOPair_t; + + /* External Variables: */ + extern Endpoint_FIFOPair_t USB_Endpoint_FIFOs[ENDPOINT_TOTAL_ENDPOINTS]; + extern volatile uint8_t USB_Endpoint_SelectedEndpoint; + extern volatile USB_EP_t* USB_Endpoint_SelectedHandle; + extern volatile Endpoint_FIFO_t* USB_Endpoint_SelectedFIFO; + + /* Inline Functions: */ + static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST + ATTR_ALWAYS_INLINE; + static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) + { + uint8_t MaskVal = 0; + uint16_t CheckBytes = 8; + + if (Bytes == 1023) + return USB_BUFSIZE_ISO_BUF1023_gc; + + while (CheckBytes < Bytes) + { + MaskVal++; + CheckBytes <<= 1; + } + + return (MaskVal << USB_BUFSIZE_DEFAULT_gp); + } + + static inline uint8_t Endpoint_GetStatus(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; + static inline uint8_t Endpoint_GetStatus(void) + { + return USB_Endpoint_SelectedHandle->STATUS; + } + + static inline void Endpoint_ClearStatus(const uint8_t Config) ATTR_CONST ATTR_ALWAYS_INLINE; + static inline void Endpoint_ClearStatus(const uint8_t Config) + { + while(USB0.INTFLAGSB & USB_RMWBUSY_bm); + + if(USB_Endpoint_SelectedEndpoint & ENDPOINT_DIR_IN) { + USB0.STATUS[USB_Endpoint_SelectedEndpoint & ENDPOINT_EPNUM_MASK].INCLR = Config; + } else { + USB0.STATUS[USB_Endpoint_SelectedEndpoint & ENDPOINT_EPNUM_MASK].OUTCLR = Config; + } + } + + static inline void Endpoint_SetStatus(const uint8_t Config) ATTR_CONST ATTR_ALWAYS_INLINE; + static inline void Endpoint_SetStatus(const uint8_t Config) + { + while(USB0.INTFLAGSB & USB_RMWBUSY_bm); + + if(USB_Endpoint_SelectedEndpoint & ENDPOINT_DIR_IN) { + USB0.STATUS[USB_Endpoint_SelectedEndpoint & ENDPOINT_EPNUM_MASK].INSET = Config; + } else { + USB0.STATUS[USB_Endpoint_SelectedEndpoint & ENDPOINT_EPNUM_MASK].OUTSET = Config; + } + } + + /* Function Prototypes: */ + bool Endpoint_ConfigureEndpoint_PRV(const uint8_t Address, + const uint8_t Config, + const uint8_t Size); + void Endpoint_ClearEndpoints(void); + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__)) + /** Default size of the default control endpoint's bank, until altered by the control endpoint bank size + * value in the device descriptor. Not available if the \c FIXED_CONTROL_ENDPOINT_SIZE token is defined. + */ + #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8 + #endif + + /* Enums: */ + /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function. + * + * \ingroup Group_EndpointRW_AVRDX + */ + enum Endpoint_WaitUntilReady_ErrorCodes_t + { + ENDPOINT_READYWAIT_NoError = 0, /**< Endpoint is ready for next packet, no error. */ + ENDPOINT_READYWAIT_EndpointStalled = 1, /**< The endpoint was stalled during the stream + * transfer by the host or device. + */ + ENDPOINT_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while + * waiting for the endpoint to become ready. + */ + ENDPOINT_READYWAIT_BusSuspended = 3, /**< The USB bus has been suspended by the host and + * no USB endpoint traffic can occur until the bus + * has resumed. + */ + ENDPOINT_READYWAIT_Timeout = 4, /**< The host failed to accept or send the next packet + * within the software timeout period set by the + * \ref USB_STREAM_TIMEOUT_MS macro. + */ + }; + + /* Inline Functions: */ + /** Selects the given endpoint address. + * + * Any endpoint operations which do not require the endpoint address to be indicated will operate on + * the currently selected endpoint. + * + * \param[in] Address Endpoint address to select. + */ + void Endpoint_SelectEndpoint(const uint8_t Address); + + /** Configures the specified endpoint address with the given endpoint type, bank size and number of hardware + * banks. Once configured, the endpoint may be read from or written to, depending on its direction. + * + * \param[in] Address Endpoint address to configure. + * + * \param[in] Type Type of endpoint to configure, a \c EP_TYPE_* mask. Not all endpoint types + * are available on Low Speed USB devices - refer to the USB 2.0 specification. + * + * \param[in] Size Size of the endpoint's bank, where packets are stored before they are transmitted + * to the USB host, or after they have been received from the USB host (depending on + * the endpoint's data direction). The bank size must indicate the maximum packet size + * that the endpoint can handle. + * + * \param[in] Banks Not implemented in AVR Dx architecture. (Number of hardware banks to use for the + * endpoint being configured). + * + * \note The default control endpoint should not be manually configured by the user application, as + * it is automatically configured by the library internally. + * \n\n + * + * \note This routine will automatically select the specified endpoint. + * + * \return Boolean \c true if the configuration succeeded, \c false otherwise. + */ + static inline bool Endpoint_ConfigureEndpoint(const uint8_t Address, + const uint8_t Type, + const uint16_t Size, + const uint8_t Banks) ATTR_ALWAYS_INLINE; + static inline bool Endpoint_ConfigureEndpoint(const uint8_t Address, + const uint8_t Type, + const uint16_t Size, + const uint8_t Banks) + { + (void)Banks; + + uint8_t EPConfigMask = (USB_TCDSBL_bm | Endpoint_BytesToEPSizeMask(Size)); + + if ((Address & ENDPOINT_EPNUM_MASK) >= ENDPOINT_TOTAL_ENDPOINTS) + return false; + + // TODO - What about ISO? + if (Size > 64) + return false; + + switch (Type) + { + case EP_TYPE_CONTROL: + EPConfigMask |= USB_TYPE_CONTROL_gc; + break; + case EP_TYPE_ISOCHRONOUS: + EPConfigMask |= USB_TYPE_ISO_gc; + break; + default: + EPConfigMask |= USB_TYPE_BULKINT_gc; + break; + } + + if (Type == EP_TYPE_CONTROL) + Endpoint_ConfigureEndpoint_PRV(Address ^ ENDPOINT_DIR_IN, EPConfigMask, Size); + + return Endpoint_ConfigureEndpoint_PRV(Address, EPConfigMask, Size); + } + + /** Indicates the number of bytes currently stored in the current endpoint's selected bank. + * + * \ingroup Group_EndpointRW_AVRDX + * + * \return Total number of bytes in the currently selected Endpoint's FIFO buffer. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline uint16_t Endpoint_BytesInEndpoint(void) + { + if (USB_Endpoint_SelectedEndpoint & ENDPOINT_DIR_IN) + return USB_Endpoint_SelectedFIFO->Position; + else + return (USB_Endpoint_SelectedFIFO->Length - USB_Endpoint_SelectedFIFO->Position); + } + + /** Get the endpoint address of the currently selected endpoint. This is typically used to save + * the currently selected endpoint so that it can be restored after another endpoint has been + * manipulated. + * + * \return Index of the currently selected endpoint. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline uint8_t Endpoint_GetCurrentEndpoint(void) + { + return USB_Endpoint_SelectedEndpoint; + } + + /** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's + * data In and Out pointers to the bank's contents. + * + * \param[in] Address Endpoint address whose FIFO buffers are to be reset. + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_ResetEndpoint(const uint8_t Address) + { + if (Address & ENDPOINT_DIR_IN) + USB_Endpoint_FIFOs[Address & ENDPOINT_EPNUM_MASK].IN.Position = 0; + else + USB_Endpoint_FIFOs[Address & ENDPOINT_EPNUM_MASK].OUT.Position = 0; + } + + /** Determines if the currently selected endpoint is enabled, but not necessarily configured. + * + * \return Boolean \c true if the currently selected endpoint is enabled, \c false otherwise. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline bool Endpoint_IsEnabled(void) + { + return true; + } + + /** Aborts all pending IN transactions on the currently selected endpoint, once the bank + * has been queued for transmission to the host via \ref Endpoint_ClearIN(). This function + * will terminate all queued transactions, resetting the endpoint banks ready for a new + * packet. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + */ + static inline void Endpoint_AbortPendingIN(void) + { + Endpoint_SetStatus(USB_BUSNAK_bm); + } + + /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint + * bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an IN + * direction). This function will return false if an error has occurred in the endpoint, if the endpoint + * is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN + * direction and the endpoint bank is full. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + * + * \return Boolean \c true if the currently selected endpoint may be read from or written to, depending + * on its direction. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline bool Endpoint_IsReadWriteAllowed(void) + { + return (USB_Endpoint_SelectedFIFO->Position < USB_Endpoint_SelectedFIFO->Length); + } + + /** Determines if the currently selected endpoint is configured. + * + * \return Boolean \c true if the currently selected endpoint has been configured, \c false otherwise. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline bool Endpoint_IsConfigured(void) + { + return ((USB_Endpoint_SelectedHandle->CTRL & USB_TYPE_gm) ? true : false); + } + + /** Determines if the selected IN endpoint is ready for a new packet to be sent to the host. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + * + * \return Boolean \c true if the current endpoint is ready for an IN packet, \c false otherwise. + */ + bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT; + + /** Determines if the selected OUT endpoint has received new packet from the host. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + * + * \return Boolean \c true if current endpoint is has received an OUT packet, \c false otherwise. + */ + bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT; + + /** Determines if the current CONTROL type endpoint has received a SETUP packet. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + * + * \return Boolean \c true if the selected endpoint has received a SETUP packet, \c false otherwise. + */ + bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT; + + /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the + * endpoint for the next packet. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + * + * \note This is not applicable for non CONTROL type endpoints. + */ + void Endpoint_ClearSETUP(void); + + /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the + * next packet and switching to the alternative endpoint bank if double banked. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + */ + void Endpoint_ClearIN(void); + + /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint + * for the next packet and switching to the alternative endpoint bank if double banked. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + */ + void Endpoint_ClearOUT(void); + + /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the + * indicated endpoint and that the current transfer sequence should be aborted. This provides a + * way for devices to indicate invalid commands to the host so that the current transfer can be + * aborted and the host can begin its own recovery sequence. + * + * The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro + * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected + * endpoint. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + */ + void Endpoint_StallTransaction(void); + + /** Clears the STALL condition on the currently selected endpoint. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_ClearStall(void) + { + USB_Endpoint_SelectedHandle->CTRL &= ~USB_DOSTALL_bm; + } + + /** Determines if the currently selected endpoint is stalled, \c false otherwise. + * + * \ingroup Group_EndpointPacketManagement_AVRDX + * + * \return Boolean \c true if the currently selected endpoint is stalled, \c false otherwise. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline bool Endpoint_IsStalled(void) + { + return ((USB_Endpoint_SelectedHandle->CTRL & USB_DOSTALL_bm) ? true : false); + } + + /** Resets the data toggle of the currently selected endpoint. */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_ResetDataToggle(void) + { + Endpoint_ClearStatus(USB_TOGGLE_bm); + } + + /** Determines the currently selected endpoint's direction. + * + * \return The currently selected endpoint's direction, as a \c ENDPOINT_DIR_* mask. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline uint8_t Endpoint_GetEndpointDirection(void) + { + return (USB_Endpoint_SelectedEndpoint & ENDPOINT_DIR_IN); + } + + /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \return Next byte in the currently selected endpoint's FIFO buffer. + */ + uint8_t Endpoint_Read_8(void) ATTR_WARN_UNUSED_RESULT; + + /** Writes one byte to the currently selected endpoint's bank, for IN direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \param[in] Data Data to write into the the currently selected endpoint's FIFO buffer. + */ + void Endpoint_Write_8(const uint8_t Data); + + /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_Discard_8(void) + { + USB_Endpoint_SelectedFIFO->Position++; + } + + /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT + * direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \return Next two bytes in the currently selected endpoint's FIFO buffer. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline uint16_t Endpoint_Read_16_LE(void) + { + uint16_t Byte0 = Endpoint_Read_8(); + uint16_t Byte1 = Endpoint_Read_8(); + + return ((Byte1 << 8) | Byte0); + } + + /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT + * direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \return Next two bytes in the currently selected endpoint's FIFO buffer. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline uint16_t Endpoint_Read_16_BE(void) + { + uint16_t Byte0 = Endpoint_Read_8(); + uint16_t Byte1 = Endpoint_Read_8(); + + return ((Byte0 << 8) | Byte1); + } + + /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN + * direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \param[in] Data Data to write to the currently selected endpoint's FIFO buffer. + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_Write_16_LE(const uint16_t Data) + { + Endpoint_Write_8(Data & 0xFF); + Endpoint_Write_8(Data >> 8); + } + + /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN + * direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \param[in] Data Data to write to the currently selected endpoint's FIFO buffer. + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_Write_16_BE(const uint16_t Data) + { + Endpoint_Write_8(Data >> 8); + Endpoint_Write_8(Data & 0xFF); + } + + /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_Discard_16(void) + { + Endpoint_Discard_8(); + Endpoint_Discard_8(); + } + + /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT + * direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \return Next four bytes in the currently selected endpoint's FIFO buffer. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline uint32_t Endpoint_Read_32_LE(void) + { + uint32_t Byte0 = Endpoint_Read_8(); + uint32_t Byte1 = Endpoint_Read_8(); + uint32_t Byte2 = Endpoint_Read_8(); + uint32_t Byte3 = Endpoint_Read_8(); + + return ((Byte3 << 24) | (Byte2 << 16) | (Byte1 << 8) | Byte0); + } + + /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT + * direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \return Next four bytes in the currently selected endpoint's FIFO buffer. + */ + ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE + static inline uint32_t Endpoint_Read_32_BE(void) + { + uint32_t Byte0 = Endpoint_Read_8(); + uint32_t Byte1 = Endpoint_Read_8(); + uint32_t Byte2 = Endpoint_Read_8(); + uint32_t Byte3 = Endpoint_Read_8(); + + return ((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3); + } + + /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN + * direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \param[in] Data Data to write to the currently selected endpoint's FIFO buffer. + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_Write_32_LE(const uint32_t Data) + { + Endpoint_Write_8(Data & 0xFF); + Endpoint_Write_8(Data >> 8); + Endpoint_Write_8(Data >> 16); + Endpoint_Write_8(Data >> 24); + } + + /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN + * direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + * + * \param[in] Data Data to write to the currently selected endpoint's FIFO buffer. + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_Write_32_BE(const uint32_t Data) + { + Endpoint_Write_8(Data >> 24); + Endpoint_Write_8(Data >> 16); + Endpoint_Write_8(Data >> 8); + Endpoint_Write_8(Data & 0xFF); + } + + /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints. + * + * \ingroup Group_EndpointPrimitiveRW_AVRDX + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_Discard_32(void) + { + Endpoint_Discard_8(); + Endpoint_Discard_8(); + Endpoint_Discard_8(); + Endpoint_Discard_8(); + } + + /* External Variables: */ + /** Global indicating the maximum packet size of the default control endpoint located at address + * 0 in the device. This value is set to the value indicated in the device descriptor in the user + * project once the USB interface is initialized into device mode. + * + * If space is an issue, it is possible to fix this to a static value by defining the control + * endpoint size in the \c FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile + * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically + * read from the descriptors at runtime and instead fixed to the given value. When used, it is + * important that the descriptor control endpoint size value matches the size given as the + * \c FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the \c FIXED_CONTROL_ENDPOINT_SIZE token + * be used in the device descriptors to ensure this. + * + * \attention This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__)) + extern uint8_t USB_Device_ControlEndpointSize; + #else + #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE + #endif + + /* Function Prototypes: */ + /** Configures a table of endpoint descriptions, in sequence. This function can be used to configure multiple + * endpoints at the same time. + * + * \note Endpoints with a zero address will be ignored, thus this function cannot be used to configure the + * control endpoint. + * + * \param[in] Table Pointer to a table of endpoint descriptions. + * \param[in] Entries Number of entries in the endpoint table to configure. + * + * \return Boolean \c true if all endpoints configured successfully, \c false otherwise. + */ + bool Endpoint_ConfigureEndpointTable(const USB_Endpoint_Table_t* const Table, + const uint8_t Entries); + + /** Completes the status stage of a control transfer on a CONTROL type endpoint automatically, + * with respect to the data direction. This is a convenience function which can be used to + * simplify user control request handling. + * + * \note This routine should not be called on non CONTROL type endpoints. + */ + void Endpoint_ClearStatusStage(void); + + /** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data + * to be read or written to it. + * + * \note This routine should not be called on CONTROL type endpoints. + * + * \ingroup Group_EndpointRW_AVRDX + * + * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum. + */ + uint8_t Endpoint_WaitUntilReady(void); + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/USB/Core/AVRDX/Host_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/Host_AVRDX.c new file mode 100644 index 000000000..6afd8340e --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Host_AVRDX.c @@ -0,0 +1,41 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#endif + +#endif diff --git a/LUFA/Drivers/USB/Core/AVRDX/PipeStream_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/PipeStream_AVRDX.c new file mode 100644 index 000000000..6afd8340e --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/PipeStream_AVRDX.c @@ -0,0 +1,41 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#endif + +#endif diff --git a/LUFA/Drivers/USB/Core/AVRDX/Pipe_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/Pipe_AVRDX.c new file mode 100644 index 000000000..da2ef5101 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Pipe_AVRDX.c @@ -0,0 +1,37 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#endif + diff --git a/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_R.c b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_R.c new file mode 100644 index 000000000..6b6a47027 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_R.c @@ -0,0 +1,86 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#if defined(TEMPLATE_FUNC_NAME) + +uint8_t TEMPLATE_FUNC_NAME (void* const Buffer, + uint16_t Length) +{ + uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length)); + + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); + + if (!(Length)) + Endpoint_ClearOUT(); + + while (Length) + { + uint8_t USB_DeviceState_LCL = USB_DeviceState; + + if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) + return ENDPOINT_RWCSTREAM_DeviceDisconnected; + else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) + return ENDPOINT_RWCSTREAM_BusSuspended; + else if (Endpoint_IsSETUPReceived()) + return ENDPOINT_RWCSTREAM_HostAborted; + + if (Endpoint_IsOUTReceived()) + { + while (Length && Endpoint_BytesInEndpoint()) + { + TEMPLATE_TRANSFER_BYTE(DataStream); + TEMPLATE_BUFFER_MOVE(DataStream, 1); + Length--; + } + + Endpoint_ClearOUT(); + } + } + + while (!(Endpoint_IsINReady())) + { + uint8_t USB_DeviceState_LCL = USB_DeviceState; + + if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) + return ENDPOINT_RWCSTREAM_DeviceDisconnected; + else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) + return ENDPOINT_RWCSTREAM_BusSuspended; + } + + return ENDPOINT_RWCSTREAM_NoError; +} + +#undef TEMPLATE_BUFFER_OFFSET +#undef TEMPLATE_BUFFER_MOVE +#undef TEMPLATE_FUNC_NAME +#undef TEMPLATE_TRANSFER_BYTE + +#endif + diff --git a/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_W.c b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_W.c new file mode 100644 index 000000000..2116f1dec --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_W.c @@ -0,0 +1,97 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#if defined(TEMPLATE_FUNC_NAME) + +uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer, + uint16_t Length) +{ + uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length)); + bool LastPacketFull = false; + + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); + + if (Length > USB_ControlRequest.wLength) + Length = USB_ControlRequest.wLength; + else if (!(Length)) + Endpoint_ClearIN(); + + while (Length || LastPacketFull) + { + uint8_t USB_DeviceState_LCL = USB_DeviceState; + + if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) + return ENDPOINT_RWCSTREAM_DeviceDisconnected; + else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) + return ENDPOINT_RWCSTREAM_BusSuspended; + else if (Endpoint_IsSETUPReceived()) + return ENDPOINT_RWCSTREAM_HostAborted; + else if (Endpoint_IsOUTReceived()) + break; + + if (Endpoint_IsINReady()) + { + uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint(); + + while (Length && (BytesInEndpoint < USB_Device_ControlEndpointSize)) + { + TEMPLATE_TRANSFER_BYTE(DataStream); + TEMPLATE_BUFFER_MOVE(DataStream, 1); + Length--; + BytesInEndpoint++; + } + + LastPacketFull = (BytesInEndpoint == USB_Device_ControlEndpointSize); + Endpoint_ClearIN(); + } + } + + while (!(Endpoint_IsOUTReceived())) + { + uint8_t USB_DeviceState_LCL = USB_DeviceState; + + if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) + return ENDPOINT_RWCSTREAM_DeviceDisconnected; + else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) + return ENDPOINT_RWCSTREAM_BusSuspended; + else if (Endpoint_IsSETUPReceived()) + return ENDPOINT_RWCSTREAM_HostAborted; + } + + return ENDPOINT_RWCSTREAM_NoError; +} + +#undef TEMPLATE_BUFFER_OFFSET +#undef TEMPLATE_BUFFER_MOVE +#undef TEMPLATE_FUNC_NAME +#undef TEMPLATE_TRANSFER_BYTE + +#endif + diff --git a/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_RW.c b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_RW.c new file mode 100644 index 000000000..c230fda03 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_RW.c @@ -0,0 +1,89 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#if defined(TEMPLATE_FUNC_NAME) + +uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length)); + uint16_t BytesInTransfer = 0; + uint8_t ErrorCode; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + { + Length -= *BytesProcessed; + TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed); + } + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + TEMPLATE_CLEAR_ENDPOINT(); + + #if !defined(INTERRUPT_CONTROL_ENDPOINT) + USB_USBTask(); + #endif + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + TEMPLATE_TRANSFER_BYTE(DataStream); + TEMPLATE_BUFFER_MOVE(DataStream, 1); + Length--; + BytesInTransfer++; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +#undef TEMPLATE_FUNC_NAME +#undef TEMPLATE_BUFFER_TYPE +#undef TEMPLATE_TRANSFER_BYTE +#undef TEMPLATE_CLEAR_ENDPOINT +#undef TEMPLATE_BUFFER_OFFSET +#undef TEMPLATE_BUFFER_MOVE + +#endif + diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c new file mode 100644 index 000000000..5a27f81a0 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c @@ -0,0 +1,165 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_USB_DRIVER +#define __INCLUDE_FROM_USB_CONTROLLER_C +#include "../USBController.h" + +#if defined(USB_CAN_BE_BOTH) +volatile uint8_t USB_CurrentMode = USB_MODE_None; +#endif + +#if !defined(USE_STATIC_OPTIONS) +volatile uint8_t USB_Options; +#endif + +/* Ugly workaround to ensure an aligned table, since __BIGGEST_ALIGNMENT__ == 1 for the 8-bit AVR-GCC toolchain */ +uint8_t USB_EndpointTable[sizeof(USB_EndpointTable_t)] ATTR_ALIGNED(2); + +void USB_Init( + #if defined(USB_CAN_BE_BOTH) + const uint8_t Mode + #endif + + #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) + , + #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS)) + void + #endif + + #if !defined(USE_STATIC_OPTIONS) + const uint8_t Options + #endif + ) +{ + #if !defined(USE_STATIC_OPTIONS) + USB_Options = Options; + #endif + + uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); + GlobalInterruptDisable(); + + USB0.EPPTR = ((intptr_t)&USB_EndpointTable[0]); + USB0.CTRLA = (USB_STFRNUM_bm | ((ENDPOINT_TOTAL_ENDPOINTS - 1) << USB_MAXEP_gp)); + + if ((USB_Options & USB_OPT_BUSEVENT_PRIHIGH) == USB_OPT_BUSEVENT_PRIHIGH) + CPUINT.LVL1VEC = USB0_BUSEVENT_vect_num; + + if ((USB_Options & USB_OPT_USBVREG_ENABLE) == USB_OPT_USBVREG_ENABLE) + SYSCFG.VUSBCTRL = SYSCFG_USBVREG_ENABLE_gc; + else + SYSCFG.VUSBCTRL = SYSCFG_USBVREG_DISABLE_gc; + + SetGlobalInterruptMask(CurrentGlobalInt); + + USB_IsInitialized = true; + + USB_ResetInterface(); +} + +void USB_Disable(void) +{ + USB_INT_DisableAllInterrupts(); + USB_INT_ClearAllInterrupts(); + + USB_Detach(); + USB_Controller_Disable(); + + USB_IsInitialized = false; +} + +void USB_ResetInterface(void) +{ + USB_Device_SetDeviceAddress(0); + + USB_INT_DisableAllInterrupts(); + USB_INT_ClearAllInterrupts(); + + USB_Controller_Reset(); + USB_Init_Device(); +} + +#if defined(USB_CAN_BE_DEVICE) +static void USB_Init_Device(void) +{ + USB_DeviceState = DEVICE_STATE_Unattached; + USB_Device_ConfigurationNumber = 0; + + #if !defined(NO_DEVICE_REMOTE_WAKEUP) + USB_Device_RemoteWakeupEnabled = false; + #endif + + #if !defined(NO_DEVICE_SELF_POWER) + USB_Device_CurrentlySelfPowered = false; + #endif + + #if !defined(FIXED_CONTROL_ENDPOINT_SIZE) + USB_Descriptor_Device_t* DeviceDescriptorPtr; + + #if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \ + !(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS)) + uint8_t DescriptorAddressSpace; + + if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr, &DescriptorAddressSpace) != NO_DESCRIPTOR) + { + if (DescriptorAddressSpace == MEMSPACE_FLASH) + USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + else if (DescriptorAddressSpace == MEMSPACE_EEPROM) + USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + else + USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; + } + #else + if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR) + { + #if defined(USE_RAM_DESCRIPTORS) + USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; + #elif defined(USE_EEPROM_DESCRIPTORS) + USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + #else + USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + #endif + } + #endif + #endif + + Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, + USB_Device_ControlEndpointSize, 1); + + USB_INT_Enable(USB_INT_BUSEVENTI); + + USB_Attach(); +} +#endif + +#endif diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h new file mode 100644 index 000000000..07d5088af --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h @@ -0,0 +1,305 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief USB Controller definitions for the AVR Dx microcontrollers. + * \copydetails Group_USBManagement_AVRDX + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_USBManagement + * \defgroup Group_USBManagement_AVRDX USB Interface Management (AVR Dx) + * \brief USB Controller definitions for the AVR Dx microcontrollers. + * + * Functions, macros, variables, enums and types related to the setup and management of the USB interface. + * + * @{ + */ + +#ifndef __USBCONTROLLER_AVRDX_H__ +#define __USBCONTROLLER_AVRDX_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../Events.h" + #include "../USBTask.h" + #include "../USBInterrupt.h" + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #if defined(MAX_ENDPOINT_INDEX) + #define ENDPOINT_TABLE_COUNT (MAX_ENDPOINT_INDEX + 1) + #else + #define ENDPOINT_TABLE_COUNT USB_MAX_ENDPOINTS + #endif + + /* Type Defines: */ + typedef struct + { + USB_EP_PAIR_t Endpoints[ENDPOINT_TABLE_COUNT]; + uint16_t FrameNum; + } ATTR_PACKED USB_EndpointTable_t; + + /* External Variables: */ + extern uint8_t USB_EndpointTable[]; + #endif + + /* Includes: */ + #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) + #include "../Device.h" + #include "../Endpoint.h" + #include "../DeviceStandardReq.h" + #include "../EndpointStream.h" + #endif + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks and Defines: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + #if !defined(F_CPU) + #error F_CPU is not defined. You must define F_CPU to a value greater than or equal to 12 MHz. + #endif + + #if ((F_CPU < 12000000UL)) + #error Invalid F_CPU specified. F_CPU must be greater than or equal to 12 MHz. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** \name USB Controller Option Masks */ + /**@{*/ + /** Sets the USB bus interrupt priority level to be low priority. The USB bus interrupt is used for Start of Frame events, bus suspend + * and resume events, bus reset events and other events related to the management of the USB bus. + */ + #define USB_OPT_BUSEVENT_PRILOW (0 << 0) + + /** Sets the USB bus interrupt priority level to be high priority. The USB bus interrupt is used for Start of Frame events, bus suspend + * and resume events, bus reset events and other events related to the management of the USB bus. + */ + #define USB_OPT_BUSEVENT_PRIHIGH (1 << 0) + + /** Disables the internal 3.3V regulator for the VUSB pin. The VUSB pin must be regulated externally */ + #define USB_OPT_USBVREG_DISABLE (0 << 2) + + /** Enables the internal 3.3V regulator for the VUSB pin. The VCC must be above ~4V */ + #define USB_OPT_USBVREG_ENABLE (1 << 2) + + /**@}*/ + + #if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__) + /** Constant for the maximum software timeout period of the USB data stream transfer functions + * (both control and standard) when in either device or host mode. If the next packet of a stream + * is not received or acknowledged within this time period, the stream function will fail. + * + * This value may be overridden in the user project makefile as the value of the + * \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch. + */ + #define USB_STREAM_TIMEOUT_MS 100 + #endif + + /* Inline Functions: */ + /** Detaches the device from the USB bus. This has the effect of removing the device from any + * attached host, ceasing USB communications. If no host is present, this prevents any host from + * enumerating the device once attached until \ref USB_Attach() is called. + */ + ATTR_ALWAYS_INLINE + static inline void USB_Detach(void) + { + USB0.CTRLB &= ~USB_ATTACH_bm; + } + + /** Attaches the device to the USB bus. This announces the device's presence to any attached + * USB host, starting the enumeration process. If no host is present, attaching the device + * will allow for enumeration once a host is connected to the device. + * + * This is inexplicably also required for proper operation while in host mode, to enable the + * attachment of a device to the host. This is despite the bit being located in the device-mode + * register and despite the datasheet making no mention of its requirement in host mode. + */ + ATTR_ALWAYS_INLINE + static inline void USB_Attach(void) + { + USB0.CTRLB |= USB_ATTACH_bm; + } + + /* Function Prototypes: */ + /** Main function to initialize and start the USB interface. Once active, the USB interface will + * allow for device connection to a host when in device mode, or for device enumeration while in + * host mode. + * + * As the USB library relies on interrupts for the device and host mode enumeration processes, + * the user must enable global interrupts before or shortly after this function is called. In + * device mode, interrupts must be enabled within 500ms of this function being called to ensure + * that the host does not time out whilst enumerating the device. In host mode, interrupts may be + * enabled at the application's leisure however enumeration will not begin of an attached device + * until after this has occurred. + * + * Calling this function when the USB interface is already initialized will cause a complete USB + * interface reset and re-enumeration. + * + * \param[in] Mode Mask indicating what mode the USB interface is to be initialized to, a value + * from the \ref USB_Modes_t enum. + * \note This parameter does not exist on devices with only one supported USB + * mode (device or host). + * + * \param[in] Options Mask indicating the options which should be used when initializing the USB + * interface to control the USB interface's behavior. This should be comprised of + * a \c USB_OPT_REG_* mask to control the regulator, a \c USB_OPT_*_PLL mask to control the + * PLL, and a \c USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device + * mode speed. + * + * \note To reduce the FLASH requirements of the library if only device or host mode is required, + * the mode can be statically set in the project makefile by defining the token \c USB_DEVICE_ONLY + * (for device mode) or \c USB_HOST_ONLY (for host mode), passing the token to the compiler + * via the -D switch. If the mode is statically set, this parameter does not exist in the + * function prototype. + * \n\n + * + * \note To reduce the FLASH requirements of the library if only fixed settings are required, + * the options may be set statically in the same manner as the mode (see the Mode parameter of + * this function). To statically set the USB options, pass in the \c USE_STATIC_OPTIONS token, + * defined to the appropriate options masks. When the options are statically set, this + * parameter does not exist in the function prototype. + * \n\n + * + * \note The mode parameter does not exist on devices where only one mode is possible, such as USB + * AVR models which only implement the USB device mode in hardware. + * + * \see \ref Group_Device for the \c USB_DEVICE_OPT_* masks. + */ + void USB_Init( + #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) + const uint8_t Mode + #endif + + #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__) + , + #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS)) + void + #endif + + #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__) + const uint8_t Options + #endif + ); + + /** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO + * memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface + * is restarted with the \ref USB_Init() function. + */ + void USB_Disable(void); + + /** Resets the interface, when already initialized. This will re-enumerate the device if already connected + * to a host, or re-enumerate an already attached device when in host mode. + */ + void USB_ResetInterface(void); + + /* Global Variables: */ + #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) + /** Indicates the mode that the USB interface is currently initialized to, a value from the + * \ref USB_Modes_t enum. + * + * \attention This variable should be treated as read-only in the user application, and never manually + * changed in value. + * + * \note When the controller is initialized into UID auto-detection mode, this variable will hold the + * currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller + * is fixed into a specific mode (either through the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY compile time + * options, or a limitation of the USB controller in the chosen device model) this will evaluate to + * a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the + * USB interface is not initialized. + */ + extern volatile uint8_t USB_CurrentMode; + #elif defined(USB_CAN_BE_HOST) + #define USB_CurrentMode USB_MODE_Host + #elif defined(USB_CAN_BE_DEVICE) + #define USB_CurrentMode USB_MODE_Device + #endif + + #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__) + /** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init() + * was called. This value will be one of the \c USB_MODE_* masks defined elsewhere in this module. + * + * \attention This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + extern volatile uint8_t USB_Options; + #elif defined(USE_STATIC_OPTIONS) + #define USB_Options USE_STATIC_OPTIONS + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Function Prototypes: */ + #if defined(__INCLUDE_FROM_USB_CONTROLLER_C) + static void USB_Init_Device(void); + #endif + + /* Inline Functions: */ + ATTR_ALWAYS_INLINE + static inline void USB_Controller_Enable(void) + { + USB0.CTRLA |= USB_ENABLE_bm; + } + + ATTR_ALWAYS_INLINE + static inline void USB_Controller_Disable(void) + { + USB0.CTRLA &= ~USB_ENABLE_bm; + } + + ATTR_ALWAYS_INLINE + static inline void USB_Controller_Reset(void) + { + USB0.CTRLA &= ~USB_ENABLE_bm; + USB0.CTRLA |= USB_ENABLE_bm; + } + + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c new file mode 100644 index 000000000..d56fbf732 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c @@ -0,0 +1,106 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "../../../../Common/Common.h" +#if (ARCH == ARCH_AVRDX) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBInterrupt.h" + +void USB_INT_DisableAllInterrupts(void) +{ + USB0.INTCTRLA = 0; + USB0.INTCTRLB = 0; +} + +void USB_INT_ClearAllInterrupts(void) +{ + USB0.INTFLAGSA = 0xFF; + USB0.INTFLAGSB = 0xFF; +} + +ISR(USB0_BUSEVENT_vect) +{ + #if !defined(NO_SOF_EVENTS) + if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI)) + { + USB_INT_Clear(USB_INT_SOFI); + + EVENT_USB_Device_StartOfFrame(); + } + #endif + + if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Suspend)) + { + USB_INT_Clear(USB_INT_BUSEVENTI_Suspend); + + #if !defined(NO_LIMITED_CONTROLLER_CONNECT) + USB_DeviceState = DEVICE_STATE_Unattached; + EVENT_USB_Device_Disconnect(); + #else + USB_DeviceState = DEVICE_STATE_Suspended; + EVENT_USB_Device_Suspend(); + #endif + } + + if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Resume)) + { + USB_INT_Clear(USB_INT_BUSEVENTI_Resume); + + if (USB_Device_ConfigurationNumber) + USB_DeviceState = DEVICE_STATE_Configured; + else + USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Addressed : DEVICE_STATE_Powered; + + #if !defined(NO_LIMITED_CONTROLLER_CONNECT) + EVENT_USB_Device_Connect(); + #else + EVENT_USB_Device_WakeUp(); + #endif + } + + if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Reset)) + { + USB_INT_Clear(USB_INT_BUSEVENTI_Reset); + + USB_DeviceState = DEVICE_STATE_Default; + USB_Device_ConfigurationNumber = 0; + + USB_Device_EnableDeviceAddress(0); + + Endpoint_ClearEndpoints(); + Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, + USB_Device_ControlEndpointSize, 1); + + EVENT_USB_Device_Reset(); + } +} + +#endif diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h new file mode 100644 index 000000000..83f9f1940 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h @@ -0,0 +1,196 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief USB Controller Interrupt definitions for the AVR Dx microcontrollers. + * + * This file contains definitions required for the correct handling of low level USB service routine interrupts + * from the USB controller. + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +#ifndef __USBINTERRUPT_AVRDX_H__ +#define __USBINTERRUPT_AVRDX_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Enums: */ + enum USB_Interrupts_t + { + USB_INT_BUSEVENTI = 1, + USB_INT_BUSEVENTI_Suspend = 2, + USB_INT_BUSEVENTI_Resume = 3, + USB_INT_BUSEVENTI_Reset = 4, + USB_INT_SOFI = 5, + }; + + /* Inline Functions: */ + ATTR_ALWAYS_INLINE + static inline void USB_INT_Enable(const uint8_t Interrupt) + { + switch (Interrupt) + { + case USB_INT_BUSEVENTI: + USB0.INTCTRLA |= (USB_SUSPEND_bm | USB_RESUME_bm | USB_RESET_bm); + break; + case USB_INT_BUSEVENTI_Suspend: + USB0.INTCTRLA |= USB_SUSPEND_bm; + break; + case USB_INT_BUSEVENTI_Resume: + USB0.INTCTRLA |= USB_RESUME_bm; + break; + case USB_INT_BUSEVENTI_Reset: + USB0.INTCTRLA |= USB_RESET_bm; + break; + case USB_INT_SOFI: + USB0.INTCTRLA |= USB_SOF_bm; + break; + default: + break; + } + } + + ATTR_ALWAYS_INLINE + static inline void USB_INT_Disable(const uint8_t Interrupt) + { + switch (Interrupt) + { + case USB_INT_BUSEVENTI: + USB0.INTCTRLA &= ~(USB_SUSPEND_bm | USB_RESUME_bm | USB_RESET_bm); + break; + case USB_INT_BUSEVENTI_Suspend: + USB0.INTCTRLA &= ~USB_SUSPEND_bm; + break; + case USB_INT_BUSEVENTI_Resume: + USB0.INTCTRLA &= ~USB_RESUME_bm; + break; + case USB_INT_BUSEVENTI_Reset: + USB0.INTCTRLA &= ~USB_RESET_bm; + break; + case USB_INT_SOFI: + USB0.INTCTRLA &= ~USB_SOF_bm; + break; + default: + break; + } + } + + ATTR_ALWAYS_INLINE + static inline void USB_INT_Clear(const uint8_t Interrupt) + { + switch (Interrupt) + { + case USB_INT_BUSEVENTI_Suspend: + USB0.INTFLAGSA = USB_SUSPEND_bm; + break; + case USB_INT_BUSEVENTI_Resume: + USB0.INTFLAGSA = USB_RESUME_bm; + break; + case USB_INT_BUSEVENTI_Reset: + USB0.INTFLAGSA = USB_RESET_bm; + break; + case USB_INT_SOFI: + USB0.INTFLAGSA = USB_SOF_bm; + break; + default: + break; + } + } + + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT + static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) + { + switch (Interrupt) + { + case USB_INT_BUSEVENTI: + return ((USB0.INTCTRLA & (USB_SUSPEND_bm | USB_RESUME_bm | USB_RESET_bm)) ? true : false); + case USB_INT_BUSEVENTI_Suspend: + return ((USB0.INTCTRLA & USB_SUSPEND_bm) ? true : false); + case USB_INT_BUSEVENTI_Resume: + return ((USB0.INTCTRLA & USB_RESUME_bm) ? true : false); + case USB_INT_BUSEVENTI_Reset: + return ((USB0.INTCTRLA & USB_RESET_bm) ? true : false); + case USB_INT_SOFI: + return ((USB0.INTCTRLA & USB_SOF_bm) ? true : false); + default: + return false; + } + } + + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT + static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) + { + switch (Interrupt) + { + case USB_INT_BUSEVENTI_Suspend: + return ((USB0.INTFLAGSA & USB_SUSPEND_bm) ? true : false); + case USB_INT_BUSEVENTI_Resume: + return ((USB0.INTFLAGSA & USB_RESUME_bm) ? true : false); + case USB_INT_BUSEVENTI_Reset: + return ((USB0.INTFLAGSA & USB_RESET_bm) ? true : false); + case USB_INT_SOFI: + return ((USB0.INTFLAGSA & USB_SOF_bm) ? true : false); + default: + return false; + } + } + + /* Includes: */ + #include "../USBMode.h" + #include "../Events.h" + #include "../USBController.h" + + /* Function Prototypes: */ + void USB_INT_ClearAllInterrupts(void); + void USB_INT_DisableAllInterrupts(void); + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + diff --git a/LUFA/Drivers/USB/Core/Device.h b/LUFA/Drivers/USB/Core/Device.h index 1a9f989a4..b336763c0 100644 --- a/LUFA/Drivers/USB/Core/Device.h +++ b/LUFA/Drivers/USB/Core/Device.h @@ -146,6 +146,8 @@ #include "UC3/Device_UC3.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/Device_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/Device_AVRDX.h" #endif /* Disable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/Core/Endpoint.h b/LUFA/Drivers/USB/Core/Endpoint.h index 034b1f178..e4c90cfc4 100644 --- a/LUFA/Drivers/USB/Core/Endpoint.h +++ b/LUFA/Drivers/USB/Core/Endpoint.h @@ -117,6 +117,8 @@ #include "UC3/Endpoint_UC3.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/Endpoint_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/Endpoint_AVRDX.h" #endif /* Disable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/Core/EndpointStream.h b/LUFA/Drivers/USB/Core/EndpointStream.h index 366ce7674..00b974d02 100644 --- a/LUFA/Drivers/USB/Core/EndpointStream.h +++ b/LUFA/Drivers/USB/Core/EndpointStream.h @@ -111,6 +111,8 @@ #include "UC3/EndpointStream_UC3.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/EndpointStream_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/EndpointStream_AVRDX.h" #endif /* Disable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/Core/StdDescriptors.h b/LUFA/Drivers/USB/Core/StdDescriptors.h index f852656b3..4fe301ef0 100644 --- a/LUFA/Drivers/USB/Core/StdDescriptors.h +++ b/LUFA/Drivers/USB/Core/StdDescriptors.h @@ -707,7 +707,7 @@ { USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ - #if (((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA)) && !defined(__DOXYGEN__)) + #if (((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || (ARCH == ARCH_AVRDX)) && !defined(__DOXYGEN__)) wchar_t UnicodeString[]; #else uint16_t UnicodeString[]; /**< String data, as unicode characters (alternatively, diff --git a/LUFA/Drivers/USB/Core/USBController.h b/LUFA/Drivers/USB/Core/USBController.h index 8aa27124f..b700386d2 100644 --- a/LUFA/Drivers/USB/Core/USBController.h +++ b/LUFA/Drivers/USB/Core/USBController.h @@ -152,6 +152,8 @@ #include "UC3/USBController_UC3.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/USBController_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/USBController_AVRDX.h" #endif /* Disable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/Core/USBInterrupt.h b/LUFA/Drivers/USB/Core/USBInterrupt.h index c947dcfc2..20614fcbf 100644 --- a/LUFA/Drivers/USB/Core/USBInterrupt.h +++ b/LUFA/Drivers/USB/Core/USBInterrupt.h @@ -62,6 +62,8 @@ #include "UC3/USBInterrupt_UC3.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/USBInterrupt_XMEGA.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/USBInterrupt_AVRDX.h" #endif /* Disable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/Core/USBMode.h b/LUFA/Drivers/USB/Core/USBMode.h index a9c89c1ce..0d81e3cbd 100644 --- a/LUFA/Drivers/USB/Core/USBMode.h +++ b/LUFA/Drivers/USB/Core/USBMode.h @@ -155,6 +155,11 @@ */ #define USB_SERIES_C4_XMEGA + /** Indicates that the target AVR microcontroller belongs to the AVR DU Family USB controller + * (i.e. AVR**DU**) when defined. + */ + #define USB_SERIES_DU_AVR + /** Indicates that the target microcontroller and compilation settings allow for the * target to be configured in USB Device mode when defined. */ @@ -245,6 +250,9 @@ #elif (defined(__AVR_ATxmega16C4__) || defined(__AVR_ATxmega32C4__)) #define USB_SERIES_C4_XMEGA #define USB_CAN_BE_DEVICE + #elif (defined(__AVR_AVR64DU28__) || defined(__AVR_AVR64DU32__)) + #define USB_SERIES_DU_AVR + #define USB_CAN_BE_DEVICE #endif #if (defined(USB_HOST_ONLY) && defined(USB_DEVICE_ONLY)) diff --git a/LUFA/Platform/AVRDX/AVRDXExperimentalInfo.txt b/LUFA/Platform/AVRDX/AVRDXExperimentalInfo.txt new file mode 100644 index 000000000..42144aac4 --- /dev/null +++ b/LUFA/Platform/AVRDX/AVRDXExperimentalInfo.txt @@ -0,0 +1 @@ +Please note that the XMEGA architecture support is EXPERIMENTAL at this time, and may be non-functional/incomplete in some areas. Please refer to the Known Issues section of the LUFA manual. \ No newline at end of file diff --git a/LUFA/Platform/AVRDX/ClockManagement.h b/LUFA/Platform/AVRDX/ClockManagement.h new file mode 100644 index 000000000..0828c4fe6 --- /dev/null +++ b/LUFA/Platform/AVRDX/ClockManagement.h @@ -0,0 +1,254 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2021. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaims all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Module Clock Driver for the AVR Dx USB microcontrollers. + * + * Clock management driver for the AVR Dx USB microcontrollers. This driver allows for the configuration + * of the various clocks within the device to clock the various peripherals. + */ + +/** \ingroup Group_PlatformDrivers_AVRDX + * \defgroup Group_PlatformDrivers_AVRDXClocks Clock Management Driver - LUFA/Platform/AVRDX/ClockManagement.h + * \brief Module Clock Driver for the AVR Dx USB microcontrollers. + * + * \section Sec_PlatformDrivers_AVRDXClocks_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - None + * + * \section Sec_PlatformDrivers_AVRDXClocks_ModDescription Module Description + * Clock management driver for the AVR Dx USB microcontrollers. This driver allows for the configuration + * of the various clocks within the device to clock the various peripherals. + * + * Usage Example: + * \code + * #include + * + * void main(void) + * { + * // Start the PLL to multiply the 2MHz RC oscillator to F_CPU and switch the CPU core to run from it + * AVRDXCLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU); + * AVRDXCLK_SetCPUClockSource(CLOCK_SRC_PLL); + * + * // Start the 32MHz internal RC oscillator and start the DFLL to increase it to F_USB using the USB SOF as a reference + * AVRDXCLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ); + * AVRDXCLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); + * } + * \endcode + * + * @{ + */ + +#ifndef _AVRDX_CLOCK_MANAGEMENT_H_ +#define _AVRDX_CLOCK_MANAGEMENT_H_ + + /* Includes: */ + #include "../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Enum for the possible external oscillator frequency ranges. */ + enum AVRDX_Extern_OSC_ClockFrequency_t + { + EXOSC_FREQ_8MHZ_MAX = CLKCTRL_FRQRANGE_8M_gc, /**< External crystal oscillator equal to or slower than 8MHz. */ + EXOSC_FREQ_16MHZ_MAX = CLKCTRL_FRQRANGE_16M_gc, /**< External crystal oscillator equal to or slower than 16MHz. */ + EXOSC_FREQ_24MHZ_MAX = CLKCTRL_FRQRANGE_24M_gc, /**< External crystal oscillator equal to or slower than 24MHz. */ + EXOSC_FREQ_32MHZ_MAX = CLKCTRL_FRQRANGE_32M_gc, /**< External crystal oscillator equal to or slower than 32MHz. */ + EXCLK = CLKCTRL_SELHF_bm, /**< External clock on XTALHF1 pin. */ + }; + + /** Enum for the possible high-frequency external oscillator startup times. */ + enum AVRDX_Extern_OSC_ClockStartup_t + { + EXOSC_START_256CLK = CLKCTRL_CSUTHF_256_gc, /**< Wait 256 clock cycles before startup. */ + EXOSC_START_1KCLK = CLKCTRL_CSUTHF_1K_gc, /**< Wait 1K clock cycles before startup. */ + EXOSC_START_4KCLK = CLKCTRL_CSUTHF_4K_gc, /**< Wait 4K clock cycles before startup. */ + }; + + /** Enum for the possible module clock sources. */ + enum AVRDX_System_ClockSource_t + { + CLOCK_SRC_INT_OSCHF = 0, /**< Clock sourced from the Internal High-Frequency Oscillator clock. */ + CLOCK_SRC_INT_32KHZ = 1, /**< Clock sourced from the Internal 32KHz Oscillator clock. */ + CLOCK_SRC_EXT_CLK = 2, /**< Clock sourced from an external clock. */ + CLOCK_SRC_EXT_OSC = 3, /**< Clock sourced from an extental high-frequency oscillator. */ + CLOCK_SRC_EXT_32KHZ = 4, /**< Clock sourced from an extental 32KHz oscillator. */ + }; + + /** Enum for the possible OSCHF Autotune sources. */ + enum AVRDX_System_OSCHFAutotune_t + { + AUTOTUNE_DISABLED = CLKCTRL_AUTOTUNE_OFF_gc, /**< OSCHF Autotune disabled. */ + AUTOTUNE_XOSC32K = CLKCTRL_AUTOTUNE_32K_gc, /**< OSCHF Autotune from the External 32KHz RC Oscillator clock . */ + AUTOTUNE_SOF_BIN = (CLKCTRL_AUTOTUNE_SOF_gc | CLKCTRL_ALGSEL_BIN_gc), /**< OSCHF Autotune with binary search from the USB Start Of Frame packets. */ + AUTOTUNE_SOF_INCR = (CLKCTRL_AUTOTUNE_SOF_gc | CLKCTRL_ALGSEL_INCR_gc), /**< OSCHF Autotune with incremental search from the USB Start Of Frame packets. */ + }; + + /* Inline Functions: */ + /** Write a value to a location protected by the AVR Dx CCP protection mechanism. This function uses inline assembly to ensure that + * the protected address is written to within four clock cycles of the CCP key being written. + * + * \param[in] Address Address to write to, a memory address protected by the CCP mechanism + * \param[in] Value Value to write to the protected location + */ + ATTR_ALWAYS_INLINE + static inline void AVRDXCLK_CCP_Write(volatile void* Address, const uint8_t Value) + { + __asm__ __volatile__ ( + "out %0, __zero_reg__" "\n\t" /* Zero RAMPZ using fixed zero value register */ + "movw r30, %1" "\n\t" /* Copy address to Z register pair */ + "out %2, %3" "\n\t" /* Write key to CCP register */ + "st Z, %4" "\n\t" /* Indirectly write value to address */ + : /* No output operands */ + : /* Input operands: */ "m" (RAMPZ), "e" (Address), "m" (CCP), "r" (CCP_IOREG_gc), "r" (Value) + : /* Clobbered registers: */ "r30", "r31" + ); + } + + /** Starts the external oscillator of the AVR Dx microcontroller, with the given options. This routine blocks until + * the oscillator is ready for use. + * + * \param[in] FreqRange Frequency range of the external oscillator, a value from \ref AVRDX_Extern_OSC_ClockFrequency_t. + * \param[in] Startup Startup time of the external oscillator, a value from \ref AVRDX_Extern_OSC_ClockStartup_t. + * + * \return Boolean \c true if the external oscillator was successfully started, \c false if invalid parameters specified. + */ + static inline bool AVRDXCLK_StartExternalOscillator(const uint8_t FreqRange, + const uint8_t Startup) ATTR_ALWAYS_INLINE; + static inline bool AVRDXCLK_StartExternalOscillator(const uint8_t FreqRange, + const uint8_t Startup) + { + AVRDXCLK_CCP_Write(&CLKCTRL.XOSCHFCTRLA, FreqRange | Startup | CLKCTRL_ENABLE_bm); + + while (!(CLKCTRL.MCLKSTATUS & CLKCTRL_EXTS_bm)); + return true; + } + + /** Stops the external oscillator of the AVR Dx microcontroller. */ + ATTR_ALWAYS_INLINE + static inline void AVRDXCLK_StopExternalOscillator(void) + { + AVRDXCLK_CCP_Write(&CLKCTRL.XOSCHFCTRLA, 0); + } + + /** Configures the OSCHF of the AVR Dx microcontroller, with the given options. This routine blocks until the OSCHF is ready for use. + * + * \attention The output frequency must be equal to or greater than 12 MHz. + * + * \param[in] Frequency Target frequency of the OSCHF's output. + * \param[in] Autotune Autotune source for the OSCHF, a value from \ref AVRDX_System_OSCHFAutotune_t. + * + * \return Boolean \c true if the OSCHF was successfully started, \c false if invalid parameters specified. + */ + static inline bool AVRDXCLK_ConfigureOSCHF(const uint32_t Frequency, const uint8_t Autotune) ATTR_ALWAYS_INLINE; + static inline bool AVRDXCLK_ConfigureOSCHF(const uint32_t Frequency, const uint8_t Autotune) + { + uint8_t ClockConfigMask = Autotune; + switch (Frequency) + { + case 12000000ul: + ClockConfigMask |= CLKCTRL_FRQSEL_12M_gc; + break; + case 16000000ul: + ClockConfigMask |= CLKCTRL_FRQSEL_16M_gc; + break; + case 20000000ul: + ClockConfigMask |= CLKCTRL_FRQSEL_20M_gc; + break; + case 24000000ul: + ClockConfigMask |= CLKCTRL_FRQSEL_24M_gc; + break; + default: + return false; + } + + AVRDXCLK_CCP_Write(&CLKCTRL.OSCHFCTRLA, ClockConfigMask); + + while (!(CLKCTRL.MCLKSTATUS & CLKCTRL_OSCHFS_bm)); + return true; + } + + + /** Sets the clock source for the main microcontroller core. The given clock source should be configured + * and ready for use before this function is called. + * + * \param[in] Source Clock source for the CPU core, a value from \ref AVRDX_System_ClockSource_t. + * + * \return Boolean \c true if the CPU core clock was successfully altered, \c false if invalid parameters specified. + */ + ATTR_ALWAYS_INLINE + static inline bool AVRDXCLK_SetCPUClockSource(const uint8_t Source) + { + uint8_t ClockSourceMask = 0; + + switch (Source) + { + case CLOCK_SRC_INT_OSCHF: + ClockSourceMask = CLKCTRL_CLKSEL_OSCHF_gc; + break; + case CLOCK_SRC_INT_32KHZ: + ClockSourceMask = CLKCTRL_CLKSEL_OSC32K_gc; + break; + case CLOCK_SRC_EXT_CLK: + case CLOCK_SRC_EXT_OSC: + ClockSourceMask = CLKCTRL_CLKSEL_EXTCLK_gc; + break; + case CLOCK_SRC_EXT_32KHZ: + ClockSourceMask = CLKCTRL_CLKSEL_XOSC32K_gc; + break; + default: + return false; + } + + uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); + GlobalInterruptDisable(); + + AVRDXCLK_CCP_Write(&CLKCTRL.MCLKCTRLA, ClockSourceMask); + + SetGlobalInterruptMask(CurrentGlobalInt); + + while (CLKCTRL.MCLKSTATUS & CLKCTRL_SOSC_bm); + return ((CLKCTRL.MCLKCTRLA & CLKCTRL_CLKSEL_gm) == ClockSourceMask); + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Platform/Platform.h b/LUFA/Platform/Platform.h index fb8398f98..a01180589 100644 --- a/LUFA/Platform/Platform.h +++ b/LUFA/Platform/Platform.h @@ -74,6 +74,8 @@ #include "UC3/InterruptManagement.h" #elif (ARCH == ARCH_XMEGA) #include "XMEGA/ClockManagement.h" + #elif (ARCH == ARCH_AVRDX) + #include "AVRDX/ClockManagement.h" #endif #endif diff --git a/LUFA/makefile b/LUFA/makefile index fb529d608..ec0b465c1 100644 --- a/LUFA/makefile +++ b/LUFA/makefile @@ -19,7 +19,7 @@ version: @echo "LUFA $(LUFA_VERSION_NUM)" LUFA_PATH := . -ARCH := {AVR8,UC3,XMEGA} +ARCH := {AVR8,UC3,XMEGA,AVRDX} DOXYGEN_OVERRIDE_PARAMS := QUIET=YES PROJECT_NUMBER=$(LUFA_VERSION_NUM) # Remove all object and associated files from the LUFA library core