From 0c993a2ae2e03cb49865e5cd0b3e3004fef84439 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 10:36:09 +0100 Subject: [PATCH 01/30] Duplicated xmega files into avr-dx folder --- .../Board/AVR_Dx/AVR64DU32_CNANO/Board.h | 86 +++ .../Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h | 119 +++ .../Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h | 181 +++++ LUFA/Drivers/Peripheral/AVR_Dx/SPI_XMEGA.h | 251 +++++++ .../Peripheral/AVR_Dx/SerialSPI_XMEGA.h | 212 ++++++ LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.c | 126 ++++ LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.h | 289 ++++++++ LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.c | 185 +++++ LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.h | 302 ++++++++ LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.c | 49 ++ LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.h | 269 +++++++ .../USB/Core/AVR_Dx/EndpointStream_XMEGA.c | 265 +++++++ .../USB/Core/AVR_Dx/EndpointStream_XMEGA.h | 658 +++++++++++++++++ LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.c | 268 +++++++ LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.h | 689 ++++++++++++++++++ LUFA/Drivers/USB/Core/AVR_Dx/Host_XMEGA.c | 41 ++ .../USB/Core/AVR_Dx/PipeStream_XMEGA.c | 41 ++ LUFA/Drivers/USB/Core/AVR_Dx/Pipe_XMEGA.c | 37 + .../Template/Template_Endpoint_Control_R.c | 86 +++ .../Template/Template_Endpoint_Control_W.c | 97 +++ .../AVR_Dx/Template/Template_Endpoint_RW.c | 89 +++ .../USB/Core/AVR_Dx/USBController_XMEGA.c | 204 ++++++ .../USB/Core/AVR_Dx/USBController_XMEGA.h | 313 ++++++++ .../USB/Core/AVR_Dx/USBInterrupt_XMEGA.c | 106 +++ .../USB/Core/AVR_Dx/USBInterrupt_XMEGA.h | 172 +++++ LUFA/Platform/AVR_Dx/ClockManagement.h | 397 ++++++++++ .../Platform/AVR_Dx/XMEGAExperimentalInfo.txt | 1 + 27 files changed, 5533 insertions(+) create mode 100644 LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h create mode 100644 LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h create mode 100644 LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h create mode 100644 LUFA/Drivers/Peripheral/AVR_Dx/SPI_XMEGA.h create mode 100644 LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_XMEGA.h create mode 100644 LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.c create mode 100644 LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.h create mode 100644 LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.c create mode 100644 LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.h create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.h create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.h create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.h create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Host_XMEGA.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_XMEGA.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Pipe_XMEGA.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_Control_R.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_Control_W.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_RW.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.h create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.c create mode 100644 LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.h create mode 100644 LUFA/Platform/AVR_Dx/ClockManagement.h create mode 100644 LUFA/Platform/AVR_Dx/XMEGAExperimentalInfo.txt diff --git a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h new file mode 100644 index 000000000..62456c43f --- /dev/null +++ b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h @@ -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. +*/ + +/** \file + * \brief Board specific information header for the Atmel XMEGA A3BU Xplained. + * \copydetails Group_BoardInfo_A3BU_XPLAINED + * + * \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_A3BU_XPLAINED A3BU_XPLAINED + * \brief Board specific information header for the Atmel XMEGA A3BU Xplained. + * + * Board specific information header for the Atmel XMEGA A3BU Xplained. + * + * @{ + */ + +#ifndef __BOARD_A3BU_XPLAINED_H__ +#define __BOARD_A3BU_XPLAINED_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../../Buttons.h" + #include "../../Dataflash.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 a hardware Dataflash mounted. */ + #define BOARD_HAS_DATAFLASH + + /** 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/AVR_Dx/AVR64DU32_CNANO/Buttons.h b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h new file mode 100644 index 000000000..6b1ada001 --- /dev/null +++ b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h @@ -0,0 +1,119 @@ +/* + 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 Atmel XMEGA A3BU Xplained. + * \copydetails Group_Buttons_A3BU_XPLAINED + * + * \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_A3BU_XPLAINED A3BU_XPLAINED + * \brief Board specific Buttons driver header for the Atmel XMEGA A3BU Xplained. + * + * Board specific Buttons driver header for the Atmel XMEGA A3BU Xplained. + * + * + * + * + * + * + *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1SW0 ButtonLowPORTE.5
BUTTONS_BUTTON2SW1 ButtonLowPORTF.1
BUTTONS_BUTTON3SW2 ButtonLowPORTF.2
+ * + * @{ + */ + +#ifndef __BUTTONS_A3BU_XPLAINED_H__ +#define __BUTTONS_A3BU_XPLAINED_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 (1 << 5) + + /** Button mask for the second button on the board. */ + #define BUTTONS_BUTTON2 (1 << 1) + + /** Button mask for the third button on the board. */ + #define BUTTONS_BUTTON3 (1 << 2) + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Buttons_Init(void) + { + PORTE.OUTCLR = BUTTONS_BUTTON1; + PORTE.PIN5CTRL = (PORT_OPC_PULLUP_gc | PORT_INVEN_bm); + + PORTF.OUTCLR = (BUTTONS_BUTTON2 | BUTTONS_BUTTON3); + PORTF.PIN1CTRL = (PORT_OPC_PULLUP_gc | PORT_INVEN_bm); + PORTF.PIN2CTRL = (PORT_OPC_PULLUP_gc | PORT_INVEN_bm); + } + + static inline void Buttons_Disable(void) + { + PORTE.OUTCLR = BUTTONS_BUTTON1; + PORTE.PIN5CTRL = 0; + + PORTF.OUTCLR = (BUTTONS_BUTTON2 | BUTTONS_BUTTON3); + PORTF.PIN1CTRL = 0; + PORTF.PIN2CTRL = 0; + } + + ATTR_WARN_UNUSED_RESULT + static inline uint8_t Buttons_GetStatus(void) + { + return ((PORTE_IN & BUTTONS_BUTTON1) | (PORTF_IN & (BUTTONS_BUTTON2 | BUTTONS_BUTTON3))); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h new file mode 100644 index 000000000..62b231477 --- /dev/null +++ b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h @@ -0,0 +1,181 @@ +/* + 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 Atmel XMEGA A3BU Xplained. + * \copydetails Group_LEDs_A3BU_XPLAINED + * + * \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_A3BU_XPLAINED A3BU_XPLAINED + * \brief Board specific LED driver header for the Atmel XMEGA A3BU Xplained. + * + * Board specific LED driver header for the Atmel XMEGA A3BU Xplained. + * + * + * + * + * + * + * + *
NameColorInfoActive LevelPort Pin
LEDS_LED1YellowLED0 LEDLowPORTR.0
LEDS_LED2YellowLED1 LEDLowPORTR.1
LEDS_LED3RedStatus Bicolour Red LEDLowPORTD.4
LEDS_LED4GreenStatus Bicolour Green LEDHighPORTD.5
+ * + * @{ + */ + +#ifndef __LEDS_A3BU_XPLAINED_H__ +#define __LEDS_A3BU_XPLAINED_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_PORTR_LEDS (LEDS_LED1 | LEDS_LED2) + #define LEDS_PORTD_LEDS (LEDS_LED3 | LEDS_LED4) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** LED mask for the first LED on the board. */ + #define LEDS_LED1 (1 << 0) + + /** LED mask for the second LED on the board. */ + #define LEDS_LED2 (1 << 1) + + /** LED mask for the third LED on the board. */ + #define LEDS_LED3 (1 << 4) + + /** LED mask for the fourth LED on the board. */ + #define LEDS_LED4 (1 << 5) + + /** LED mask for all the LEDs on the board. */ + #define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4) + + /** LED mask for none of the board LEDs. */ + #define LEDS_NO_LEDS 0 + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void LEDs_Init(void) + { + PORTR.DIRSET = LEDS_PORTR_LEDS; + PORTR.OUTCLR = LEDS_PORTR_LEDS; + + PORTCFG.MPCMASK = LEDS_PORTR_LEDS; + PORTR.PIN0CTRL = PORT_INVEN_bm; + + PORTD.DIRSET = LEDS_PORTD_LEDS; + PORTD.OUTCLR = LEDS_PORTD_LEDS; + + PORTD.PIN4CTRL = PORT_INVEN_bm; + } + + static inline void LEDs_Disable(void) + { + PORTR.DIRCLR = LEDS_PORTR_LEDS; + PORTR.OUTCLR = LEDS_PORTR_LEDS; + + PORTCFG.MPCMASK = 0; + PORTR.PIN0CTRL = LEDS_PORTR_LEDS; + + PORTD.DIRCLR = LEDS_PORTD_LEDS; + PORTD.OUTCLR = LEDS_PORTD_LEDS; + + PORTD.PIN4CTRL = 0; + } + + static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) + { + PORTR_OUTSET = LEDMask & LEDS_PORTR_LEDS; + PORTD_OUTSET = LEDMask & LEDS_PORTD_LEDS; + } + + static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) + { + PORTR_OUTCLR = LEDMask & LEDS_PORTR_LEDS; + PORTD_OUTCLR = LEDMask & LEDS_PORTD_LEDS; + } + + static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) + { + PORTR_OUTCLR = LEDS_PORTR_LEDS; + PORTD_OUTCLR = LEDS_PORTD_LEDS; + + PORTR_OUTSET = (LEDMask & LEDS_PORTR_LEDS); + PORTD_OUTSET = (LEDMask & LEDS_PORTD_LEDS); + } + + static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, + const uint8_t ActiveMask) + { + PORTR_OUTCLR = (LEDMask & LEDS_PORTR_LEDS); + PORTD_OUTCLR = (LEDMask & LEDS_PORTD_LEDS); + + PORTR_OUTSET = (ActiveMask & LEDS_PORTR_LEDS); + PORTD_OUTSET = (ActiveMask & LEDS_PORTD_LEDS); + } + + static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) + { + PORTR_OUTTGL = (LEDMask & LEDS_PORTR_LEDS); + PORTD_OUTTGL = (LEDMask & LEDS_PORTD_LEDS); + } + + ATTR_WARN_UNUSED_RESULT + static inline uint8_t LEDs_GetLEDs(void) + { + return ((PORTR_OUT & LEDS_PORTR_LEDS) | (PORTD_OUT & LEDS_PORTD_LEDS)); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SPI_XMEGA.h b/LUFA/Drivers/Peripheral/AVR_Dx/SPI_XMEGA.h new file mode 100644 index 000000000..ea2ad762b --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVR_Dx/SPI_XMEGA.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 (XMEGA) + * + * On-chip SPI driver for the XMEGA 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_XMEGA SPI Peripheral Driver (XMEGA) + * + * \section Sec_SPI_XMEGA_ModDescription Module Description + * Driver for the hardware SPI port(s) available on XMEGA AVR 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_XMEGA_H__ +#define __SPI_XMEGA_H__ + + /* Includes: */ + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_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 | (1 << SPI_PRESCALER_gp)) + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 16. */ + #define SPI_SPEED_FCPU_DIV_16 (1 << SPI_PRESCALER_gp) + + /** 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 | (2 << SPI_PRESCALER_gp)) + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 64. */ + #define SPI_SPEED_FCPU_DIV_64 (2 << SPI_PRESCALER_gp) + + /** SPI prescaler mask for \ref SPI_Init(). Divides the system clock by a factor of 128. */ + #define SPI_SPEED_FCPU_DIV_128 (3 << SPI_PRESCALER_gp) + /**@}*/ + + /** \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_MODE1_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_MODE0_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->CTRL = (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->CTRL &= ~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->CTRL & 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->STATUS & 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->STATUS & 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->STATUS & SPI_IF_bm)); + return SPI->DATA; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_XMEGA.h b/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_XMEGA.h new file mode 100644 index 000000000..c1b418976 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_XMEGA.h @@ -0,0 +1,212 @@ +/* + 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 (XMEGA) + * + * On-chip Master SPI mode USART driver for the XMEGA AVR 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_XMEGA Master SPI Mode Serial USART Peripheral Driver (XMEGA) + * + * \section Sec_SerialSPI_XMEGA_ModDescription Module Description + * On-chip serial USART driver for the XMEGA AVR 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_XMEGA_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_XMEGA_H__ +#define __SERIAL_SPI_XMEGA_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_UBBRVAL(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) + { + uint16_t BaudValue = SERIAL_SPI_UBBRVAL(BaudRate); + + USART->BAUDCTRLB = (BaudValue >> 8); + USART->BAUDCTRLA = (BaudValue & 0xFF); + + 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->DATA = DataByte; + while (!(USART->STATUS & USART_TXCIF_bm)); + USART->STATUS = USART_TXCIF_bm; + return USART->DATA; + } + + /** 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/AVR_Dx/Serial_XMEGA.c b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.c new file mode 100644 index 000000000..e7b5d64fc --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.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_XMEGA) + +#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/AVR_Dx/Serial_XMEGA.h b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.h new file mode 100644 index 000000000..b7ebd5627 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.h @@ -0,0 +1,289 @@ +/* + 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 (XMEGA) + * + * On-chip serial USART driver for the XMEGA AVR 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_XMEGA Serial USART Peripheral Driver (XMEGA) + * + * \section Sec_Serial_XMEGA_ModDescription Module Description + * On-chip serial USART driver for the XMEGA AVR 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_XMEGA_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_XMEGA_H__ +#define __SERIAL_XMEGA_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 when the \c U2X (double speed) bit is + * not set. + * + * \param[in] Baud Target serial UART baud rate. + * + * \return Closest UBRR register value for the given UART frequency. + */ + #define SERIAL_UBBRVAL(Baud) ((((F_CPU / 16) + (Baud / 2)) / (Baud)) - 1) + + /** Macro for calculating the baud value from a given baud rate when the \c U2X (double speed) bit is + * set. + * + * \param[in] Baud Target serial UART baud rate. + * + * \return Closest UBRR register value for the given UART frequency. + */ + #define SERIAL_2X_UBBRVAL(Baud) ((((F_CPU / 8) + (Baud / 2)) / (Baud)) - 1) + + /* 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) + { + uint16_t BaudValue = (DoubleSpeed ? SERIAL_2X_UBBRVAL(BaudRate) : SERIAL_UBBRVAL(BaudRate)); + + USART->BAUDCTRLB = (BaudValue >> 8); + USART->BAUDCTRLA = (BaudValue & 0xFF); + + USART->CTRLC = (USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc); + USART->CTRLB = (USART_RXEN_bm | USART_TXEN_bm | (DoubleSpeed ? USART_CLK2X_bm : 0)); + } + + /** 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->DATA = 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->DATA; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.c b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.c new file mode 100644 index 000000000..fdaa4ac25 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.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_XMEGA) + +#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->MASTER.ADDR = SlaveAddress; + + TimeoutRemaining = (TimeoutMS * 100); + while (TimeoutRemaining) + { + uint8_t status = TWI->MASTER.STATUS; + + if ((status & (TWI_MASTER_WIF_bm | TWI_MASTER_ARBLOST_bm)) == (TWI_MASTER_WIF_bm | TWI_MASTER_ARBLOST_bm)) + { + TWI->MASTER.ADDR = SlaveAddress; + } + else if ((status & (TWI_MASTER_WIF_bm | TWI_MASTER_RXACK_bm)) == (TWI_MASTER_WIF_bm | TWI_MASTER_RXACK_bm)) + { + TWI_StopTransmission(TWI); + return TWI_ERROR_SlaveResponseTimeout; + } + else if (status & (TWI_MASTER_WIF_bm | TWI_MASTER_RIF_bm)) + { + return TWI_ERROR_NoError; + } + + _delay_us(10); + TimeoutRemaining--; + } + + if (!(TimeoutRemaining)) { + if (TWI->MASTER.STATUS & TWI_MASTER_CLKHOLD_bm) { + TWI_StopTransmission(TWI); + } + } + + return TWI_ERROR_BusCaptureTimeout; +} + +bool TWI_SendByte(TWI_t* const TWI, + const uint8_t Byte) +{ + TWI->MASTER.DATA = Byte; + + while (!(TWI->MASTER.STATUS & TWI_MASTER_WIF_bm)); + + return (TWI->MASTER.STATUS & TWI_MASTER_WIF_bm) && !(TWI->MASTER.STATUS & TWI_MASTER_RXACK_bm); +} + +bool TWI_ReceiveByte(TWI_t* const TWI, + uint8_t* const Byte, + const bool LastByte) +{ + if ((TWI->MASTER.STATUS & (TWI_MASTER_BUSERR_bm | TWI_MASTER_ARBLOST_bm)) == (TWI_MASTER_BUSERR_bm | TWI_MASTER_ARBLOST_bm)) { + return false; + } + + while (!(TWI->MASTER.STATUS & TWI_MASTER_RIF_bm)); + + *Byte = TWI->MASTER.DATA; + + if (LastByte) + TWI->MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc; + else + TWI->MASTER.CTRLC = TWI_MASTER_CMD_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/AVR_Dx/TWI_XMEGA.h b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.h new file mode 100644 index 000000000..2312b36fb --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.h @@ -0,0 +1,302 @@ +/* + 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 (XMEGA) + * + * On-chip TWI driver for the XMEGA 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_XMEGA TWI Peripheral Driver (XMEGA) + * + * \section Sec_TWI_XMEGA_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_XMEGA_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_XMEGA_H__ +#define __TWI_XMEGA_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 XMEGA 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->CTRL = 0x00; + TWI->MASTER.BAUD = Baud; + TWI->MASTER.CTRLA = TWI_MASTER_ENABLE_bm; + TWI->MASTER.CTRLB = 0; + TWI->MASTER.STATUS = TWI_MASTER_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->MASTER.CTRLA &= ~TWI_MASTER_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->MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_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/USB/Core/AVR_Dx/Device_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.c new file mode 100644 index 000000000..44e135fc2 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.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_XMEGA) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "../Device.h" + +void USB_Device_SendRemoteWakeup(void) +{ + USB.CTRLB |= USB_RWAKEUP_bm; +} + +#endif + +#endif + diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.h new file mode 100644 index 000000000..f990b6728 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.h @@ -0,0 +1,269 @@ +/* + 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 XMEGA microcontrollers. + * \copydetails Group_Device_XMEGA + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_Device + * \defgroup Group_Device_XMEGA Device Management (XMEGA) + * \brief USB Device definitions for the AVR XMEGA microcontrollers. + * + * Architecture specific USB Device definitions for the Atmel AVR XMEGA microcontrollers. + * + * @{ + */ + +#ifndef __USBDEVICE_XMEGA_H__ +#define __USBDEVICE_XMEGA_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBController.h" + #include "../StdDescriptors.h" + #include "../USBInterrupt.h" + #include "../Endpoint.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + #if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)) + #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. + #endif + + #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: */ + /** \name USB Device Mode Option Masks */ + /**@{*/ + /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the + * USB interface should be initialized in low speed (1.5Mb/s) mode. + * + * \note Low Speed mode is not available on all USB AVR models. + * \n + * + * \note Restrictions apply on the number, size and type of endpoints which can be used + * when running in low speed mode - refer to the USB 2.0 specification. + */ + #define USB_DEVICE_OPT_LOWSPEED (1 << 0) + + #if (F_USB > 6000000) + /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the + * USB interface should be initialized in full speed (12Mb/s) mode. + */ + #define USB_DEVICE_OPT_FULLSPEED (0 << 0) + #endif + /**@}*/ + + #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(NVM_PROD_SIGNATURES_t, COORDY1) - offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0)))) + + /** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller + * model. + */ + #define INTERNAL_SERIAL_START_ADDRESS offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) + #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*)USB.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) + { + USB.INTCTRLA |= USB_SOFIE_bm; + } + + /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the + * \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode. + * + * \note 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) + { + USB.INTCTRLA &= ~USB_SOFIE_bm; + } + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Inline Functions: */ + ATTR_ALWAYS_INLINE + static inline void USB_Device_SetLowSpeed(void) + { + USB.CTRLA &= ~USB_SPEED_bm; + } + + ATTR_ALWAYS_INLINE + static inline void USB_Device_SetFullSpeed(void) + { + USB.CTRLA |= USB_SPEED_bm; + } + + ATTR_ALWAYS_INLINE + static inline void USB_Device_SetDeviceAddress(const uint8_t Address) + { + (void)Address; + + /* No implementation for XMEGA architecture */ + } + + ATTR_ALWAYS_INLINE + static inline void USB_Device_EnableDeviceAddress(const uint8_t Address) + { + USB.ADDR = Address; + } + + ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT + static inline bool USB_Device_IsAddressSet(void) + { + return ((USB.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 = INTERNAL_SERIAL_START_ADDRESS; + + for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++) + { + uint8_t SerialByte; + + NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; + SerialByte = pgm_read_byte(SigReadAddress); + NVM.CMD = 0; + + 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/AVR_Dx/EndpointStream_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.c new file mode 100644 index 000000000..85164f7c7 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.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_XMEGA) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#include "EndpointStream_XMEGA.h" + +#if !defined(CONTROL_ONLY_DEVICE) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 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/AVR_Dx/EndpointStream_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.h new file mode 100644 index 000000000..ce7710cee --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.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 XMEGA microcontrollers. + * \copydetails Group_EndpointStreamRW_XMEGA + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointStreamRW + * \defgroup Group_EndpointStreamRW_XMEGA Read/Write of Multi-Byte Streams (XMEGA) + * \brief Endpoint data stream transmission and reception management for the Atmel AVR XMEGA architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + * + * @{ + */ + +#ifndef __ENDPOINT_STREAM_XMEGA_H__ +#define __ENDPOINT_STREAM_XMEGA_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../USBTask.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Function Prototypes: */ + /** \name Stream functions for null data */ + /**@{*/ + + /** Reads and discards the given number of bytes from the currently selected endpoint's bank, + * discarding fully read packets from the host as needed. The last packet is not automatically + * discarded once the remaining bytes has been read; the user is responsible for manually + * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of bytes to discard via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending + * full packets to the host as needed. The last packet is not automatically sent once the + * remaining bytes have been written; the user is responsible for manually sending the last + * packet to the host via the \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Length Number of zero bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed); + + /**@}*/ + + /** \name Stream functions for RAM source/destination data */ + /**@{*/ + + /** Writes the given number of bytes to the endpoint from the given buffer in little endian, + * sending full packets to the host as needed. The last packet filled is not automatically sent; + * the user is responsible for manually sending the last written packet to the host via the + * \ref Endpoint_ClearIN() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes full while there is still data to process (and after the current + * packet transmission has been initiated) the BytesProcessed location will be updated with the + * total number of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_LE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** Writes the given number of bytes to the endpoint from the given buffer in big endian, + * sending full packets to the host as needed. The last packet filled is not automatically sent; + * the user is responsible for manually sending the last written packet to the host via the + * \ref Endpoint_ClearIN() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be written at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Stream_BE(const void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads the given number of bytes from the endpoint from the given buffer in little endian, + * discarding fully read packets from the host as needed. The last packet is not automatically + * discarded once the remaining bytes has been read; the user is responsible for manually + * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. + * + * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, + * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid + * storage location, the transfer will instead be performed as a series of chunks. Each time + * the endpoint bank becomes empty while there is still data to process (and after the current + * packet has been acknowledged) the BytesProcessed location will be updated with the total number + * of bytes processed in the stream, and the function will exit with an error code of + * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed + * in the user code - to continue the transfer, call the function again with identical parameters + * and it will resume until the BytesProcessed value reaches the total transfer length. + * + * Single Stream Transfer Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * + * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * NULL)) != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * Partial Stream Transfers Example: + * \code + * uint8_t DataStream[512]; + * uint8_t ErrorCode; + * uint16_t BytesProcessed; + * + * BytesProcessed = 0; + * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream), + * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer) + * { + * // Stream not yet complete - do other actions here, abort if required + * } + * + * if (ErrorCode != ENDPOINT_RWSTREAM_NoError) + * { + * // Stream failed to complete - check ErrorCode here + * } + * \endcode + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_LE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** Reads the given number of bytes from the endpoint from the given buffer in big endian, + * discarding fully read packets from the host as needed. The last packet is not automatically + * discarded once the remaining bytes has been read; the user is responsible for manually + * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. + * + * \note This routine should not be used on CONTROL type endpoints. + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current + * transaction should be updated, \c NULL if the entire stream should be read at once. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Stream_BE(void* const Buffer, + uint16_t Length, + uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1); + + /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian, + * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared + * in both failure and success states; the user is responsible for manually clearing the 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/AVR_Dx/Endpoint_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.c new file mode 100644 index 000000000..cc2dd8c87 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.c @@ -0,0 +1,268 @@ +/* + 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_XMEGA) + +#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 ((USB_Endpoint_SelectedHandle->STATUS & USB_EP_BUSNACK0_bm) ? true : false); +} + +bool Endpoint_IsOUTReceived(void) +{ + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); + + if (USB_Endpoint_SelectedHandle->STATUS & USB_EP_TRNCOMPL0_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 (USB_Endpoint_SelectedHandle->STATUS & USB_EP_SETUP_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); + USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_SETUP_bm | USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); + USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; + USB_Endpoint_SelectedFIFO->Position = 0; + + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); + USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; + USB_Endpoint_SelectedFIFO->Position = 0; +} + +void Endpoint_ClearIN(void) +{ + USB_Endpoint_SelectedHandle->CNT = USB_Endpoint_SelectedFIFO->Position; + USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); + USB_Endpoint_SelectedFIFO->Position = 0; +} + +void Endpoint_ClearOUT(void) +{ + USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); + USB_Endpoint_SelectedFIFO->Position = 0; +} + +void Endpoint_StallTransaction(void) +{ + USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_bm; + + if ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_TYPE_gm) == USB_EP_TYPE_CONTROL_gc) + { + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint ^ ENDPOINT_DIR_IN); + USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_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*)USB.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; + USB_Endpoint_SelectedHandle->STATUS = (Address & ENDPOINT_DIR_IN) ? USB_EP_BUSNACK0_bm : 0; + 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*)USB.EPPTR)->Endpoints[EPNum].IN.CTRL = 0; + ((USB_EndpointTable_t*)USB.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/AVR_Dx/Endpoint_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.h new file mode 100644 index 000000000..4af0d919c --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.h @@ -0,0 +1,689 @@ +/* + 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 XMEGA microcontrollers. + * \copydetails Group_EndpointManagement_XMEGA + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_EndpointRW + * \defgroup Group_EndpointRW_XMEGA Endpoint Data Reading and Writing (XMEGA) + * \brief Endpoint data read/write definitions for the Atmel AVR XMEGA architecture. + * + * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints. + */ + +/** \ingroup Group_EndpointPrimitiveRW + * \defgroup Group_EndpointPrimitiveRW_XMEGA Read/Write of Primitive Data Types (XMEGA) + * \brief Endpoint primitive read/write definitions for the Atmel AVR XMEGA 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_XMEGA Endpoint Packet Management (XMEGA) + * \brief Endpoint packet management definitions for the Atmel AVR XMEGA architecture. + * + * Functions, macros, variables, enums and types related to packet management of endpoints. + */ + +/** \ingroup Group_EndpointManagement + * \defgroup Group_EndpointManagement_XMEGA Endpoint Management (XMEGA) + * \brief Endpoint management definitions for the Atmel AVR XMEGA 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_XMEGA_H__ +#define __ENDPOINT_XMEGA_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; + + while (CheckBytes < Bytes) + { + MaskVal++; + CheckBytes <<= 1; + } + + return (MaskVal << USB_EP_BUFSIZE_gp); + } + + /* 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_XMEGA + */ + 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 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) + { + uint8_t EPConfigMask = (USB_EP_INTDSBL_bm | ((Banks > 1) ? USB_EP_PINGPONG_bm : 0) | Endpoint_BytesToEPSizeMask(Size)); + + if ((Address & ENDPOINT_EPNUM_MASK) >= ENDPOINT_TOTAL_ENDPOINTS) + return false; + + // TODO - Fix once limitations are lifted + EPConfigMask &= ~USB_EP_PINGPONG_bm; + if (Size > 64) + return false; + + switch (Type) + { + case EP_TYPE_CONTROL: + EPConfigMask |= USB_EP_TYPE_CONTROL_gc; + break; + case EP_TYPE_ISOCHRONOUS: + EPConfigMask |= USB_EP_TYPE_ISOCHRONOUS_gc; + break; + default: + EPConfigMask |= USB_EP_TYPE_BULK_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_XMEGA + * + * \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_XMEGA + */ + static inline void Endpoint_AbortPendingIN(void) + { + USB_Endpoint_SelectedHandle->STATUS |= USB_EP_BUSNACK0_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_XMEGA + * + * \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_EP_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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + */ + 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_XMEGA + */ + 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_XMEGA + */ + void Endpoint_StallTransaction(void); + + /** Clears the STALL condition on the currently selected endpoint. + * + * \ingroup Group_EndpointPacketManagement_XMEGA + */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_ClearStall(void) + { + USB_Endpoint_SelectedHandle->CTRL &= ~USB_EP_STALL_bm; + } + + /** Determines if the currently selected endpoint is stalled, \c false otherwise. + * + * \ingroup Group_EndpointPacketManagement_XMEGA + * + * \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_EP_STALL_bm) ? true : false); + } + + /** Resets the data toggle of the currently selected endpoint. */ + ATTR_ALWAYS_INLINE + static inline void Endpoint_ResetDataToggle(void) + { + USB_Endpoint_SelectedHandle->STATUS &= ~USB_EP_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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + */ + 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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + */ + 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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + * + * \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_XMEGA + */ + 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_XMEGA + * + * \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/AVR_Dx/Host_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/Host_XMEGA.c new file mode 100644 index 000000000..6694d60cc --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Host_XMEGA.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_XMEGA) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#endif + +#endif diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_XMEGA.c new file mode 100644 index 000000000..6694d60cc --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_XMEGA.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_XMEGA) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#endif + +#endif diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Pipe_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/Pipe_XMEGA.c new file mode 100644 index 000000000..da2ef5101 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Pipe_XMEGA.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/AVR_Dx/Template/Template_Endpoint_Control_R.c b/LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_Control_R.c new file mode 100644 index 000000000..6b6a47027 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/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/AVR_Dx/Template/Template_Endpoint_Control_W.c b/LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_Control_W.c new file mode 100644 index 000000000..2116f1dec --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/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/AVR_Dx/Template/Template_Endpoint_RW.c b/LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_RW.c new file mode 100644 index 000000000..c230fda03 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/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/AVR_Dx/USBController_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.c new file mode 100644 index 000000000..ce38ac33d --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.c @@ -0,0 +1,204 @@ +/* + 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_XMEGA) + +#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) + 1]; + +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(); + + NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; + USB.CAL0 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL0)); + USB.CAL1 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL1)); + NVM.CMD = NVM_CMD_NO_OPERATION_gc; + + /* Ugly workaround to ensure an aligned table, since __BIGGEST_ALIGNMENT__ == 1 for the 8-bit AVR-GCC toolchain */ + USB.EPPTR = ((intptr_t)&USB_EndpointTable[1] & ~(1 << 0)); + USB.CTRLA = (USB_STFRNUM_bm | ((ENDPOINT_TOTAL_ENDPOINTS - 1) << USB_MAXEP_gp)); + + if ((USB_Options & USB_OPT_BUSEVENT_PRIHIGH) == USB_OPT_BUSEVENT_PRIHIGH) + USB.INTCTRLA = (3 << USB_INTLVL_gp); + else if ((USB_Options & USB_OPT_BUSEVENT_PRIMED) == USB_OPT_BUSEVENT_PRIMED) + USB.INTCTRLA = (2 << USB_INTLVL_gp); + else + USB.INTCTRLA = (1 << USB_INTLVL_gp); + + SetGlobalInterruptMask(CurrentGlobalInt); + + #if defined(USB_CAN_BE_BOTH) + USB_CurrentMode = Mode; + #endif + + 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) +{ + uint8_t PrescalerNeeded; + + #if defined(USB_DEVICE_OPT_FULLSPEED) + if (USB_Options & USB_DEVICE_OPT_LOWSPEED) + PrescalerNeeded = F_USB / 6000000; + else + PrescalerNeeded = F_USB / 48000000; + #else + PrescalerNeeded = F_USB / 6000000; + #endif + + uint8_t DividerIndex = 0; + while (PrescalerNeeded > 0) + { + DividerIndex++; + PrescalerNeeded >>= 1; + } + + CLK.USBCTRL = (DividerIndex - 1) << CLK_USBPSDIV_gp; + + if (USB_Options & USB_OPT_PLLCLKSRC) + CLK.USBCTRL |= (CLK_USBSRC_PLL_gc | CLK_USBSEN_bm); + else + CLK.USBCTRL |= (CLK_USBSRC_RC32M_gc | CLK_USBSEN_bm); + + 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 + + if (USB_Options & USB_DEVICE_OPT_LOWSPEED) + USB_Device_SetLowSpeed(); + else + USB_Device_SetFullSpeed(); + + 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/AVR_Dx/USBController_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.h new file mode 100644 index 000000000..4ded8495c --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.h @@ -0,0 +1,313 @@ +/* + 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 XMEGA microcontrollers. + * \copydetails Group_USBManagement_XMEGA + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_USBManagement + * \defgroup Group_USBManagement_XMEGA USB Interface Management (XMEGA) + * \brief USB Controller definitions for the AVR XMEGA microcontrollers. + * + * Functions, macros, variables, enums and types related to the setup and management of the USB interface. + * + * @{ + */ + +#ifndef __USBCONTROLLER_XMEGA_H__ +#define __USBCONTROLLER_XMEGA_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + #include "../USBMode.h" + #include "../Events.h" + #include "../USBTask.h" + #include "../USBInterrupt.h" + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #if defined(MAX_ENDPOINT_INDEX) + #define ENDPOINT_TABLE_COUNT (MAX_ENDPOINT_INDEX + 1) + #else + #define ENDPOINT_TABLE_COUNT 16 + #endif + + /* Type Defines: */ + typedef struct + { + struct + { + USB_EP_t OUT; + USB_EP_t IN; + } 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_USB) + #error F_USB is not defined. You must define F_USB to the frequency of the unprescaled USB controller clock in your project makefile. + #endif + + #if ((F_USB % 6000000) || (F_USB < 6000000)) + #error Invalid F_USB specified. F_USB must be a multiple of 6MHz for USB Low Speed operation, and a multiple of 48MHz for Full Speed operation. + #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 << 2) | (0 << 1)) + + /** Sets the USB bus interrupt priority level to be medium priority. The USB bus interrupt is used for Start of Frame events, bus suspend + * and resume events, bus reset events and other events related to the management of the USB bus. + */ + #define USB_OPT_BUSEVENT_PRIMED ((0 << 2) | (1 << 1)) + + /** Sets the USB bus interrupt priority level to be high priority. The USB bus interrupt is used for Start of Frame events, bus suspend + * and resume events, bus reset events and other events related to the management of the USB bus. + */ + #define USB_OPT_BUSEVENT_PRIHIGH ((1 << 2) | (0 << 1)) + + /** Sets the USB controller to source its clock from the internal RC 32MHz clock, once it has been DFLL calibrated to 48MHz. */ + #define USB_OPT_RC32MCLKSRC (0 << 3) + + /** Sets the USB controller to source its clock from the internal PLL. */ + #define USB_OPT_PLLCLKSRC (1 << 3) + /**@}*/ + + #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) + { + USB.CTRLB &= ~USB_ATTACH_bm; + } + + /** Attaches the device to the USB bus. This announces the device's presence to any attached + * USB host, starting the enumeration process. If no host is present, attaching the device + * will allow for enumeration once a host is connected to the device. + * + * This is inexplicably also required for proper operation while in host mode, to enable the + * attachment of a device to the host. This is despite the bit being located in the device-mode + * register and despite the datasheet making no mention of its requirement in host mode. + */ + ATTR_ALWAYS_INLINE + static inline void USB_Attach(void) + { + USB.CTRLB |= USB_ATTACH_bm; + } + + /* Function Prototypes: */ + /** Main function to initialize and start the USB interface. Once active, the USB interface will + * allow for device connection to a host when in device mode, or for device enumeration while in + * host mode. + * + * As the USB library relies on interrupts for the device and host mode enumeration processes, + * the user must enable global interrupts before or shortly after this function is called. In + * device mode, interrupts must be enabled within 500ms of this function being called to ensure + * that the host does not time out whilst enumerating the device. In host mode, interrupts may be + * enabled at the application's leisure however enumeration will not begin of an attached device + * until after this has occurred. + * + * Calling this function when the USB interface is already initialized will cause a complete USB + * interface reset and re-enumeration. + * + * \param[in] Mode 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) + { + USB.CTRLA |= USB_ENABLE_bm; + } + + ATTR_ALWAYS_INLINE + static inline void USB_Controller_Disable(void) + { + USB.CTRLA &= ~USB_ENABLE_bm; + } + + ATTR_ALWAYS_INLINE + static inline void USB_Controller_Reset(void) + { + USB.CTRLA &= ~USB_ENABLE_bm; + USB.CTRLA |= USB_ENABLE_bm; + } + + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.c new file mode 100644 index 000000000..398708e98 --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.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_XMEGA) + +#define __INCLUDE_FROM_USB_DRIVER +#include "../USBInterrupt.h" + +void USB_INT_DisableAllInterrupts(void) +{ + USB.INTCTRLA &= USB_INTLVL_gm; + USB.INTCTRLB = 0; +} + +void USB_INT_ClearAllInterrupts(void) +{ + USB.INTFLAGSACLR = 0xFF; + USB.INTFLAGSBCLR = 0xFF; +} + +ISR(USB_BUSEVENT_vect) +{ + #if !defined(NO_SOF_EVENTS) + if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI)) + { + USB_INT_Clear(USB_INT_SOFI); + + EVENT_USB_Device_StartOfFrame(); + } + #endif + + if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Suspend)) + { + USB_INT_Clear(USB_INT_BUSEVENTI_Suspend); + + #if !defined(NO_LIMITED_CONTROLLER_CONNECT) + USB_DeviceState = DEVICE_STATE_Unattached; + EVENT_USB_Device_Disconnect(); + #else + USB_DeviceState = DEVICE_STATE_Suspended; + EVENT_USB_Device_Suspend(); + #endif + } + + if (USB_INT_HasOccurred(USB_INT_BUSEVENTI_Resume)) + { + USB_INT_Clear(USB_INT_BUSEVENTI_Resume); + + if (USB_Device_ConfigurationNumber) + USB_DeviceState = DEVICE_STATE_Configured; + else + USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_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/AVR_Dx/USBInterrupt_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.h new file mode 100644 index 000000000..2dc92afcd --- /dev/null +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.h @@ -0,0 +1,172 @@ +/* + 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 XMEGA microcontrollers. + * + * This file contains definitions required for the correct handling of low level USB service routine interrupts + * from the USB controller. + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +#ifndef __USBINTERRUPT_XMEGA_H__ +#define __USBINTERRUPT_XMEGA_H__ + + /* Includes: */ + #include "../../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Enums: */ + enum USB_Interrupts_t + { + USB_INT_BUSEVENTI = 1, + USB_INT_BUSEVENTI_Suspend = 2, + USB_INT_BUSEVENTI_Resume = 3, + USB_INT_BUSEVENTI_Reset = 4, + USB_INT_SOFI = 5, + }; + + /* Inline Functions: */ + ATTR_ALWAYS_INLINE + static inline void USB_INT_Enable(const uint8_t Interrupt) + { + switch (Interrupt) + { + case USB_INT_BUSEVENTI: + USB.INTCTRLA |= USB_BUSEVIE_bm; + break; + case USB_INT_SOFI: + USB.INTCTRLA |= USB_SOFIE_bm; + break; + default: + break; + } + } + + ATTR_ALWAYS_INLINE + static inline void USB_INT_Disable(const uint8_t Interrupt) + { + switch (Interrupt) + { + case USB_INT_BUSEVENTI: + USB.INTCTRLA &= ~USB_BUSEVIE_bm; + break; + case USB_INT_SOFI: + USB.INTCTRLA &= ~USB_SOFIE_bm; + break; + default: + break; + } + } + + ATTR_ALWAYS_INLINE + static inline void USB_INT_Clear(const uint8_t Interrupt) + { + switch (Interrupt) + { + case USB_INT_BUSEVENTI_Suspend: + USB.INTFLAGSACLR = USB_SUSPENDIF_bm; + break; + case USB_INT_BUSEVENTI_Resume: + USB.INTFLAGSACLR = USB_RESUMEIF_bm; + break; + case USB_INT_BUSEVENTI_Reset: + USB.INTFLAGSACLR = USB_RSTIF_bm; + break; + case USB_INT_SOFI: + USB.INTFLAGSACLR = USB_SOFIF_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 ((USB.INTCTRLA & USB_BUSEVIE_bm) ? true : false); + case USB_INT_SOFI: + return ((USB.INTCTRLA & USB_SOFIE_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 ((USB.INTFLAGSACLR & USB_SUSPENDIF_bm) ? true : false); + case USB_INT_BUSEVENTI_Resume: + return ((USB.INTFLAGSACLR & USB_RESUMEIF_bm) ? true : false); + case USB_INT_BUSEVENTI_Reset: + return ((USB.INTFLAGSACLR & USB_RSTIF_bm) ? true : false); + case USB_INT_SOFI: + return ((USB.INTFLAGSACLR & USB_SOFIF_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/Platform/AVR_Dx/ClockManagement.h b/LUFA/Platform/AVR_Dx/ClockManagement.h new file mode 100644 index 000000000..fe57e8c40 --- /dev/null +++ b/LUFA/Platform/AVR_Dx/ClockManagement.h @@ -0,0 +1,397 @@ +/* + 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 USB XMEGA microcontrollers. + * + * Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration + * of the various clocks within the device to clock the various peripherals. + */ + +/** \ingroup Group_PlatformDrivers_XMEGA + * \defgroup Group_PlatformDrivers_XMEGAClocks Clock Management Driver - LUFA/Platform/XMEGA/ClockManagement.h + * \brief Module Clock Driver for the AVR USB XMEGA microcontrollers. + * + * \section Sec_PlatformDrivers_XMEGAClocks_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - None + * + * \section Sec_PlatformDrivers_XMEGAClocks_ModDescription Module Description + * Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration + * of the various clocks within the device to clock the various peripherals. + * + * Usage Example: + * \code + * #include + * + * void main(void) + * { + * // Start the PLL to multiply the 2MHz RC oscillator to F_CPU and switch the CPU core to run from it + * XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU); + * XMEGACLK_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 + * XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ); + * XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); + * } + * \endcode + * + * @{ + */ + +#ifndef _XMEGA_CLOCK_MANAGEMENT_H_ +#define _XMEGA_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 XMEGA_Extern_OSC_ClockFrequency_t + { + EXOSC_FREQ_2MHZ_MAX = OSC_FRQRANGE_04TO2_gc, /**< External crystal oscillator equal to or slower than 2MHz. */ + EXOSC_FREQ_9MHZ_MAX = OSC_FRQRANGE_2TO9_gc, /**< External crystal oscillator equal to or slower than 9MHz. */ + EXOSC_FREQ_12MHZ_MAX = OSC_FRQRANGE_9TO12_gc, /**< External crystal oscillator equal to or slower than 12MHz. */ + EXOSC_FREQ_16MHZ_MAX = OSC_FRQRANGE_12TO16_gc, /**< External crystal oscillator equal to or slower than 16MHz. */ + }; + + /** Enum for the possible external oscillator startup times. */ + enum XMEGA_Extern_OSC_ClockStartup_t + { + EXOSC_START_6CLK = OSC_XOSCSEL_EXTCLK_gc, /**< Wait 6 clock cycles before startup (external clock). */ + EXOSC_START_32KCLK = OSC_XOSCSEL_32KHz_gc, /**< Wait 32K clock cycles before startup (32.768KHz crystal). */ + EXOSC_START_256CLK = OSC_XOSCSEL_XTAL_256CLK_gc, /**< Wait 256 clock cycles before startup. */ + EXOSC_START_1KCLK = OSC_XOSCSEL_XTAL_1KCLK_gc, /**< Wait 1K clock cycles before startup. */ + EXOSC_START_16KCLK = OSC_XOSCSEL_XTAL_16KCLK_gc, /**< Wait 16K clock cycles before startup. */ + }; + + /** Enum for the possible module clock sources. */ + enum XMEGA_System_ClockSource_t + { + CLOCK_SRC_INT_RC2MHZ = 0, /**< Clock sourced from the Internal 2MHz RC Oscillator clock. */ + CLOCK_SRC_INT_RC32MHZ = 1, /**< Clock sourced from the Internal 32MHz RC Oscillator clock. */ + CLOCK_SRC_INT_RC32KHZ = 2, /**< Clock sourced from the Internal 32KHz RC Oscillator clock. */ + CLOCK_SRC_XOSC = 3, /**< Clock sourced from the External Oscillator clock. */ + CLOCK_SRC_PLL = 4, /**< Clock sourced from the Internal PLL clock. */ + }; + + /** Enum for the possible DFLL clock reference sources. */ + enum XMEGA_System_DFLLReference_t + { + DFLL_REF_INT_RC32KHZ = 0, /**< Reference clock sourced from the Internal 32KHz RC Oscillator clock. */ + DFLL_REF_EXT_RC32KHZ = 1, /**< Reference clock sourced from the External 32KHz RC Oscillator clock connected to TOSC pins. */ + DFLL_REF_INT_USBSOF = 2, /**< Reference clock sourced from the USB Start Of Frame packets. */ + }; + + /* Inline Functions: */ + /** Write a value to a location protected by the XMEGA 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 XMEGACLK_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 XMEGA microcontroller, with the given options. This routine blocks until + * the oscillator is ready for use. + * + * \param[in] FreqRange Frequency range of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockFrequency_t. + * \param[in] Startup Startup time of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockStartup_t. + * + * \return Boolean \c true if the external oscillator was successfully started, \c false if invalid parameters specified. + */ + static inline bool XMEGACLK_StartExternalOscillator(const uint8_t FreqRange, + const uint8_t Startup) ATTR_ALWAYS_INLINE; + static inline bool XMEGACLK_StartExternalOscillator(const uint8_t FreqRange, + const uint8_t Startup) + { + OSC.XOSCCTRL = (FreqRange | ((Startup == EXOSC_START_32KCLK) ? OSC_X32KLPM_bm : 0) | Startup); + OSC.CTRL |= OSC_XOSCEN_bm; + + while (!(OSC.STATUS & OSC_XOSCRDY_bm)); + return true; + } + + /** Stops the external oscillator of the XMEGA microcontroller. */ + ATTR_ALWAYS_INLINE + static inline void XMEGACLK_StopExternalOscillator(void) + { + OSC.CTRL &= ~OSC_XOSCEN_bm; + } + + /** Starts the given internal oscillator of the XMEGA microcontroller, with the given options. This routine blocks until + * the oscillator is ready for use. + * + * \param[in] Source Internal oscillator to start, a value from \ref XMEGA_System_ClockSource_t. + * + * \return Boolean \c true if the internal oscillator was successfully started, \c false if invalid parameters specified. + */ + ATTR_ALWAYS_INLINE + static inline bool XMEGACLK_StartInternalOscillator(const uint8_t Source) + { + switch (Source) + { + case CLOCK_SRC_INT_RC2MHZ: + OSC.CTRL |= OSC_RC2MEN_bm; + while (!(OSC.STATUS & OSC_RC2MRDY_bm)); + return true; + case CLOCK_SRC_INT_RC32MHZ: + OSC.CTRL |= OSC_RC32MEN_bm; + while (!(OSC.STATUS & OSC_RC32MRDY_bm)); + return true; + case CLOCK_SRC_INT_RC32KHZ: + OSC.CTRL |= OSC_RC32KEN_bm; + while (!(OSC.STATUS & OSC_RC32KRDY_bm)); + return true; + default: + return false; + } + } + + /** Stops the given internal oscillator of the XMEGA microcontroller. + * + * \param[in] Source Internal oscillator to stop, a value from \ref XMEGA_System_ClockSource_t. + * + * \return Boolean \c true if the internal oscillator was successfully stopped, \c false if invalid parameters specified. + */ + ATTR_ALWAYS_INLINE + static inline bool XMEGACLK_StopInternalOscillator(const uint8_t Source) + { + switch (Source) + { + case CLOCK_SRC_INT_RC2MHZ: + OSC.CTRL &= ~OSC_RC2MEN_bm; + return true; + case CLOCK_SRC_INT_RC32MHZ: + OSC.CTRL &= ~OSC_RC32MEN_bm; + return true; + case CLOCK_SRC_INT_RC32KHZ: + OSC.CTRL &= ~OSC_RC32KEN_bm; + return true; + default: + return false; + } + } + + /** Starts the PLL of the XMEGA microcontroller, with the given options. This routine blocks until the PLL is ready for use. + * + * \attention The output frequency must be equal to or greater than the source frequency. + * + * \param[in] Source Clock source for the PLL, a value from \ref XMEGA_System_ClockSource_t. + * \param[in] SourceFreq Frequency of the PLL's clock source, in Hz. + * \param[in] Frequency Target frequency of the PLL's output. + * + * \return Boolean \c true if the PLL was successfully started, \c false if invalid parameters specified. + */ + static inline bool XMEGACLK_StartPLL(const uint8_t Source, + const uint32_t SourceFreq, + const uint32_t Frequency) ATTR_ALWAYS_INLINE; + static inline bool XMEGACLK_StartPLL(const uint8_t Source, + const uint32_t SourceFreq, + const uint32_t Frequency) + { + uint8_t MulFactor = (Frequency / SourceFreq); + + if (SourceFreq > Frequency) + return false; + + if (MulFactor > 31) + return false; + + switch (Source) + { + case CLOCK_SRC_INT_RC2MHZ: + OSC.PLLCTRL = (OSC_PLLSRC_RC2M_gc | MulFactor); + break; + case CLOCK_SRC_INT_RC32MHZ: + OSC.PLLCTRL = (OSC_PLLSRC_RC32M_gc | MulFactor); + break; + case CLOCK_SRC_XOSC: + OSC.PLLCTRL = (OSC_PLLSRC_XOSC_gc | MulFactor); + break; + default: + return false; + } + + OSC.CTRL |= OSC_PLLEN_bm; + + while (!(OSC.STATUS & OSC_PLLRDY_bm)); + return true; + } + + /** Stops the PLL of the XMEGA microcontroller. */ + ATTR_ALWAYS_INLINE + static inline void XMEGACLK_StopPLL(void) + { + OSC.CTRL &= ~OSC_PLLEN_bm; + } + + /** Starts the DFLL of the XMEGA microcontroller, with the given options. + * + * \param[in] Source RC Clock source for the DFLL, a value from \ref XMEGA_System_ClockSource_t. + * \param[in] Reference Reference clock source for the DFLL, an value from \ref XMEGA_System_DFLLReference_t. + * \param[in] Frequency Target frequency of the DFLL's output. + * + * \return Boolean \c true if the DFLL was successfully started, \c false if invalid parameters specified. + */ + static inline bool XMEGACLK_StartDFLL(const uint8_t Source, + const uint8_t Reference, + const uint32_t Frequency) ATTR_ALWAYS_INLINE; + static inline bool XMEGACLK_StartDFLL(const uint8_t Source, + const uint8_t Reference, + const uint32_t Frequency) + { + uint16_t DFLLCompare = (Frequency / 1024); + + switch (Source) + { + case CLOCK_SRC_INT_RC2MHZ: + OSC.DFLLCTRL |= (Reference << OSC_RC2MCREF_bp); + DFLLRC2M.COMP1 = (DFLLCompare & 0xFF); + DFLLRC2M.COMP2 = (DFLLCompare >> 8); + DFLLRC2M.CTRL = DFLL_ENABLE_bm; + break; + case CLOCK_SRC_INT_RC32MHZ: + OSC.DFLLCTRL |= (Reference << OSC_RC32MCREF_gp); + DFLLRC32M.COMP1 = (DFLLCompare & 0xFF); + DFLLRC32M.COMP2 = (DFLLCompare >> 8); + + if (Reference == DFLL_REF_INT_USBSOF) + { + NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; + DFLLRC32M.CALA = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBRCOSCA)); + DFLLRC32M.CALB = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBRCOSC)); + NVM.CMD = 0; + } + + DFLLRC32M.CTRL = DFLL_ENABLE_bm; + break; + default: + return false; + } + + return true; + } + + /** Stops the given DFLL of the XMEGA microcontroller. + * + * \param[in] Source RC Clock source for the DFLL to be stopped, a value from \ref XMEGA_System_ClockSource_t. + * + * \return Boolean \c true if the DFLL was successfully stopped, \c false if invalid parameters specified. + */ + ATTR_ALWAYS_INLINE + static inline bool XMEGACLK_StopDFLL(const uint8_t Source) + { + switch (Source) + { + case CLOCK_SRC_INT_RC2MHZ: + DFLLRC2M.CTRL = 0; + break; + case CLOCK_SRC_INT_RC32MHZ: + DFLLRC32M.CTRL = 0; + break; + default: + return false; + } + + 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 XMEGA_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 XMEGACLK_SetCPUClockSource(const uint8_t Source) + { + uint8_t ClockSourceMask = 0; + + switch (Source) + { + case CLOCK_SRC_INT_RC2MHZ: + ClockSourceMask = CLK_SCLKSEL_RC2M_gc; + break; + case CLOCK_SRC_INT_RC32MHZ: + ClockSourceMask = CLK_SCLKSEL_RC32M_gc; + break; + case CLOCK_SRC_INT_RC32KHZ: + ClockSourceMask = CLK_SCLKSEL_RC32K_gc; + break; + case CLOCK_SRC_XOSC: + ClockSourceMask = CLK_SCLKSEL_XOSC_gc; + break; + case CLOCK_SRC_PLL: + ClockSourceMask = CLK_SCLKSEL_PLL_gc; + break; + default: + return false; + } + + uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); + GlobalInterruptDisable(); + + XMEGACLK_CCP_Write(&CLK.CTRL, ClockSourceMask); + + SetGlobalInterruptMask(CurrentGlobalInt); + + Delay_MS(1); + return (CLK.CTRL == ClockSourceMask); + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ + diff --git a/LUFA/Platform/AVR_Dx/XMEGAExperimentalInfo.txt b/LUFA/Platform/AVR_Dx/XMEGAExperimentalInfo.txt new file mode 100644 index 000000000..42144aac4 --- /dev/null +++ b/LUFA/Platform/AVR_Dx/XMEGAExperimentalInfo.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 From a975c00daf3c69193e1540fd7c4212fe0b5d4c9b Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 10:48:24 +0100 Subject: [PATCH 02/30] renaming filenames from XMEGA to AVR_Dx --- LUFA/Drivers/Peripheral/AVR_Dx/{SPI_XMEGA.h => SPI_AVR_Dx.h} | 0 .../Peripheral/AVR_Dx/{SerialSPI_XMEGA.h => SerialSPI_AVR_Dx.h} | 0 .../Drivers/Peripheral/AVR_Dx/{Serial_XMEGA.c => Serial_AVR_Dx.c} | 0 .../Drivers/Peripheral/AVR_Dx/{Serial_XMEGA.h => Serial_AVR_Dx.h} | 0 LUFA/Drivers/Peripheral/AVR_Dx/{TWI_XMEGA.c => TWI_AVR_Dx.c} | 0 LUFA/Drivers/Peripheral/AVR_Dx/{TWI_XMEGA.h => TWI_AVR_Dx.h} | 0 LUFA/Drivers/USB/Core/AVR_Dx/{Device_XMEGA.c => Device_AVR_Dx.c} | 0 LUFA/Drivers/USB/Core/AVR_Dx/{Device_XMEGA.h => Device_AVR_Dx.h} | 0 .../AVR_Dx/{EndpointStream_XMEGA.c => EndpointStream_AVR_Dx.c} | 0 .../AVR_Dx/{EndpointStream_XMEGA.h => EndpointStream_AVR_Dx.h} | 0 .../USB/Core/AVR_Dx/{Endpoint_XMEGA.c => Endpoint_AVR_Dx.c} | 0 .../USB/Core/AVR_Dx/{Endpoint_XMEGA.h => Endpoint_AVR_Dx.h} | 0 LUFA/Drivers/USB/Core/AVR_Dx/{Host_XMEGA.c => Host_AVR_Dx.c} | 0 .../USB/Core/AVR_Dx/{PipeStream_XMEGA.c => PipeStream_AVR_Dx.c} | 0 LUFA/Drivers/USB/Core/AVR_Dx/{Pipe_XMEGA.c => Pipe_AVR_Dx.c} | 0 .../Core/AVR_Dx/{USBController_XMEGA.c => USBController_AVR_Dx.c} | 0 .../Core/AVR_Dx/{USBController_XMEGA.h => USBController_AVR_Dx.h} | 0 .../Core/AVR_Dx/{USBInterrupt_XMEGA.c => USBInterrupt_AVR_Dx.c} | 0 .../Core/AVR_Dx/{USBInterrupt_XMEGA.h => USBInterrupt_AVR_Dx.h} | 0 .../{XMEGAExperimentalInfo.txt => AVR_DxExperimentalInfo.txt} | 0 20 files changed, 0 insertions(+), 0 deletions(-) rename LUFA/Drivers/Peripheral/AVR_Dx/{SPI_XMEGA.h => SPI_AVR_Dx.h} (100%) rename LUFA/Drivers/Peripheral/AVR_Dx/{SerialSPI_XMEGA.h => SerialSPI_AVR_Dx.h} (100%) rename LUFA/Drivers/Peripheral/AVR_Dx/{Serial_XMEGA.c => Serial_AVR_Dx.c} (100%) rename LUFA/Drivers/Peripheral/AVR_Dx/{Serial_XMEGA.h => Serial_AVR_Dx.h} (100%) rename LUFA/Drivers/Peripheral/AVR_Dx/{TWI_XMEGA.c => TWI_AVR_Dx.c} (100%) rename LUFA/Drivers/Peripheral/AVR_Dx/{TWI_XMEGA.h => TWI_AVR_Dx.h} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{Device_XMEGA.c => Device_AVR_Dx.c} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{Device_XMEGA.h => Device_AVR_Dx.h} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{EndpointStream_XMEGA.c => EndpointStream_AVR_Dx.c} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{EndpointStream_XMEGA.h => EndpointStream_AVR_Dx.h} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{Endpoint_XMEGA.c => Endpoint_AVR_Dx.c} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{Endpoint_XMEGA.h => Endpoint_AVR_Dx.h} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{Host_XMEGA.c => Host_AVR_Dx.c} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{PipeStream_XMEGA.c => PipeStream_AVR_Dx.c} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{Pipe_XMEGA.c => Pipe_AVR_Dx.c} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{USBController_XMEGA.c => USBController_AVR_Dx.c} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{USBController_XMEGA.h => USBController_AVR_Dx.h} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{USBInterrupt_XMEGA.c => USBInterrupt_AVR_Dx.c} (100%) rename LUFA/Drivers/USB/Core/AVR_Dx/{USBInterrupt_XMEGA.h => USBInterrupt_AVR_Dx.h} (100%) rename LUFA/Platform/AVR_Dx/{XMEGAExperimentalInfo.txt => AVR_DxExperimentalInfo.txt} (100%) diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SPI_XMEGA.h b/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/SPI_XMEGA.h rename to LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_XMEGA.h b/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_XMEGA.h rename to LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.c b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.c rename to LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.h b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/Serial_XMEGA.h rename to LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.c b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.c rename to LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.h b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/TWI_XMEGA.h rename to LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.c rename to LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Device_XMEGA.h rename to LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.c rename to LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_XMEGA.h rename to LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.c rename to LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_XMEGA.h rename to LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Host_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Host_XMEGA.c rename to LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_XMEGA.c rename to LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_AVR_Dx.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Pipe_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/Pipe_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Pipe_XMEGA.c rename to LUFA/Drivers/USB/Core/AVR_Dx/Pipe_AVR_Dx.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.c rename to LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/USBController_XMEGA.h rename to LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.c b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.c rename to LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.h b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_XMEGA.h rename to LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h diff --git a/LUFA/Platform/AVR_Dx/XMEGAExperimentalInfo.txt b/LUFA/Platform/AVR_Dx/AVR_DxExperimentalInfo.txt similarity index 100% rename from LUFA/Platform/AVR_Dx/XMEGAExperimentalInfo.txt rename to LUFA/Platform/AVR_Dx/AVR_DxExperimentalInfo.txt From 6c8b03fa7f2d214daaff99f209d4a8e409d1fa90 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 11:10:09 +0100 Subject: [PATCH 03/30] Search-and-replace XMEGA to AVR Dx in files --- LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h | 14 +-- .../Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h | 16 +-- .../Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c | 2 +- .../Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h | 16 +-- LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c | 2 +- LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h | 16 +-- LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c | 2 +- LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h | 16 +-- .../USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c | 4 +- .../USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h | 12 +-- .../Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c | 2 +- .../Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h | 78 +++++++------- LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c | 2 +- .../USB/Core/AVR_Dx/PipeStream_AVR_Dx.c | 2 +- .../USB/Core/AVR_Dx/USBController_AVR_Dx.c | 2 +- .../USB/Core/AVR_Dx/USBController_AVR_Dx.h | 12 +-- .../USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c | 2 +- .../USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h | 6 +- LUFA/Platform/AVR_Dx/ClockManagement.h | 102 +++++++++--------- 19 files changed, 154 insertions(+), 154 deletions(-) diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h index ea2ad762b..ddd8d6ce0 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h +++ b/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h @@ -29,19 +29,19 @@ */ /** \file - * \brief SPI Peripheral Driver (XMEGA) + * \brief SPI Peripheral Driver (AVR Dx) * - * On-chip SPI driver for the XMEGA microcontrollers. + * 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_XMEGA SPI Peripheral Driver (XMEGA) + * \defgroup Group_SPI_AVRDX SPI Peripheral Driver (AVR Dx) * - * \section Sec_SPI_XMEGA_ModDescription Module Description - * Driver for the hardware SPI port(s) available on XMEGA AVR microcontroller models. This + * \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. * @@ -71,8 +71,8 @@ * @{ */ -#ifndef __SPI_XMEGA_H__ -#define __SPI_XMEGA_H__ +#ifndef __SPI_AVRDX_H__ +#define __SPI_AVRDX_H__ /* Includes: */ #include "../../../Common/Common.h" diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h index c1b418976..cd04ed351 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h +++ b/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h @@ -29,24 +29,24 @@ */ /** \file - * \brief Master SPI Mode Serial USART Peripheral Driver (XMEGA) + * \brief Master SPI Mode Serial USART Peripheral Driver (AVR Dx) * - * On-chip Master SPI mode USART driver for the XMEGA AVR microcontrollers. + * 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_XMEGA Master SPI Mode Serial USART Peripheral Driver (XMEGA) + * \defgroup Group_SerialSPI_AVRDX Master SPI Mode Serial USART Peripheral Driver (AVR Dx) * - * \section Sec_SerialSPI_XMEGA_ModDescription Module Description - * On-chip serial USART driver for the XMEGA AVR microcontrollers. + * \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_XMEGA_ExampleUsage Example Usage + * \section Sec_SerialSPI_AVRDX_ExampleUsage Example Usage * The following snippet is an example of how this module may be used within a typical * application. * @@ -71,8 +71,8 @@ * @{ */ -#ifndef __SERIAL_SPI_XMEGA_H__ -#define __SERIAL_SPI_XMEGA_H__ +#ifndef __SERIAL_SPI_AVRDX_H__ +#define __SERIAL_SPI_AVRDX_H__ /* Includes: */ #include "../../../Common/Common.h" diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c index e7b5d64fc..09e3ebf0d 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c +++ b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c @@ -29,7 +29,7 @@ */ #include "../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_SERIAL_C #include "../Serial.h" diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h index b7ebd5627..5fdfa52fb 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h +++ b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h @@ -29,24 +29,24 @@ */ /** \file - * \brief Serial USART Peripheral Driver (XMEGA) + * \brief Serial USART Peripheral Driver (AVR Dx) * - * On-chip serial USART driver for the XMEGA AVR microcontrollers. + * 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_XMEGA Serial USART Peripheral Driver (XMEGA) + * \defgroup Group_Serial_AVRDX Serial USART Peripheral Driver (AVR Dx) * - * \section Sec_Serial_XMEGA_ModDescription Module Description - * On-chip serial USART driver for the XMEGA AVR microcontrollers. + * \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_XMEGA_ExampleUsage Example Usage + * \section Sec_Serial_AVRDX_ExampleUsage Example Usage * The following snippet is an example of how this module may be used within a typical * application. * @@ -64,8 +64,8 @@ * @{ */ -#ifndef __SERIAL_XMEGA_H__ -#define __SERIAL_XMEGA_H__ +#ifndef __SERIAL_AVRDX_H__ +#define __SERIAL_AVRDX_H__ /* Includes: */ #include "../../../Common/Common.h" diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c index fdaa4ac25..1e44d1127 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c +++ b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c @@ -29,7 +29,7 @@ */ #include "../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_TWI_C #include "../TWI.h" diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h index 2312b36fb..01432ea8c 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h +++ b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h @@ -29,24 +29,24 @@ */ /** \file - * \brief TWI Peripheral Driver (XMEGA) + * \brief TWI Peripheral Driver (AVR Dx) * - * On-chip TWI driver for the XMEGA Family of AVR microcontrollers. + * 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_XMEGA TWI Peripheral Driver (XMEGA) + * \defgroup Group_TWI_AVRDX TWI Peripheral Driver (AVR Dx) * - * \section Sec_TWI_XMEGA_ModDescription Module Description + * \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_XMEGA_ExampleUsage Example Usage + * \section Sec_TWI_AVRDX_ExampleUsage Example Usage * The following snippet is an example of how this module may be used within a typical * application. * @@ -112,8 +112,8 @@ * @{ */ -#ifndef __TWI_XMEGA_H__ -#define __TWI_XMEGA_H__ +#ifndef __TWI_AVRDX_H__ +#define __TWI_AVRDX_H__ /* Includes: */ #include "../../../Common/Common.h" @@ -176,7 +176,7 @@ * 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 XMEGA microcontroller datasheet. + * 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. diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c index 44e135fc2..a6bf8a362 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c @@ -29,7 +29,7 @@ */ #include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_USB_DRIVER #include "../USBMode.h" diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h index f990b6728..33e48dc8c 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h @@ -29,24 +29,24 @@ */ /** \file - * \brief USB Device definitions for the AVR XMEGA microcontrollers. - * \copydetails Group_Device_XMEGA + * \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_XMEGA Device Management (XMEGA) - * \brief USB Device definitions for the AVR XMEGA microcontrollers. + * \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 XMEGA microcontrollers. + * Architecture specific USB Device definitions for the Atmel AVR Dx microcontrollers. * * @{ */ -#ifndef __USBDEVICE_XMEGA_H__ -#define __USBDEVICE_XMEGA_H__ +#ifndef __USBDEVICE_AVRDX_H__ +#define __USBDEVICE_AVRDX_H__ /* Includes: */ #include "../../../../Common/Common.h" @@ -210,7 +210,7 @@ { (void)Address; - /* No implementation for XMEGA architecture */ + /* No implementation for AVR Dx architecture */ } ATTR_ALWAYS_INLINE diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c index 85164f7c7..4d6d1a5d8 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c @@ -29,14 +29,14 @@ */ #include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_USB_DRIVER #include "../USBMode.h" #if defined(USB_CAN_BE_DEVICE) -#include "EndpointStream_XMEGA.h" +#include "EndpointStream_AVRDX.h" #if !defined(CONTROL_ONLY_DEVICE) uint8_t Endpoint_Discard_Stream(uint16_t Length, diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h index ce7710cee..f82c162e4 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h @@ -29,16 +29,16 @@ */ /** \file - * \brief Endpoint data stream transmission and reception management for the AVR XMEGA microcontrollers. - * \copydetails Group_EndpointStreamRW_XMEGA + * \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_XMEGA Read/Write of Multi-Byte Streams (XMEGA) - * \brief Endpoint data stream transmission and reception management for the Atmel AVR XMEGA architecture. + * \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. @@ -46,8 +46,8 @@ * @{ */ -#ifndef __ENDPOINT_STREAM_XMEGA_H__ -#define __ENDPOINT_STREAM_XMEGA_H__ +#ifndef __ENDPOINT_STREAM_AVRDX_H__ +#define __ENDPOINT_STREAM_AVRDX_H__ /* Includes: */ #include "../../../../Common/Common.h" diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c index cc2dd8c87..82d902be8 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c @@ -29,7 +29,7 @@ */ #include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_USB_DRIVER #include "../USBMode.h" diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h index 4af0d919c..83f66455b 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h @@ -29,38 +29,38 @@ */ /** \file - * \brief USB Endpoint definitions for the AVR XMEGA microcontrollers. - * \copydetails Group_EndpointManagement_XMEGA + * \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_XMEGA Endpoint Data Reading and Writing (XMEGA) - * \brief Endpoint data read/write definitions for the Atmel AVR XMEGA architecture. + * \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_XMEGA Read/Write of Primitive Data Types (XMEGA) - * \brief Endpoint primitive read/write definitions for the Atmel AVR XMEGA architecture. + * \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_XMEGA Endpoint Packet Management (XMEGA) - * \brief Endpoint packet management definitions for the Atmel AVR XMEGA architecture. + * \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_XMEGA Endpoint Management (XMEGA) - * \brief Endpoint management definitions for the Atmel AVR XMEGA architecture. + * \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 @@ -69,8 +69,8 @@ * @{ */ -#ifndef __ENDPOINT_XMEGA_H__ -#define __ENDPOINT_XMEGA_H__ +#ifndef __ENDPOINT_AVRDX_H__ +#define __ENDPOINT_AVRDX_H__ /* Includes: */ #include "../../../../Common/Common.h" @@ -163,7 +163,7 @@ /* Enums: */ /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function. * - * \ingroup Group_EndpointRW_XMEGA + * \ingroup Group_EndpointRW_AVRDX */ enum Endpoint_WaitUntilReady_ErrorCodes_t { @@ -257,7 +257,7 @@ /** Indicates the number of bytes currently stored in the current endpoint's selected bank. * - * \ingroup Group_EndpointRW_XMEGA + * \ingroup Group_EndpointRW_AVRDX * * \return Total number of bytes in the currently selected Endpoint's FIFO buffer. */ @@ -311,7 +311,7 @@ * will terminate all queued transactions, resetting the endpoint banks ready for a new * packet. * - * \ingroup Group_EndpointPacketManagement_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX */ static inline void Endpoint_AbortPendingIN(void) { @@ -324,7 +324,7 @@ * 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_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX * * \return Boolean \c true if the currently selected endpoint may be read from or written to, depending * on its direction. @@ -347,7 +347,7 @@ /** Determines if the selected IN endpoint is ready for a new packet to be sent to the host. * - * \ingroup Group_EndpointPacketManagement_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX * * \return Boolean \c true if the current endpoint is ready for an IN packet, \c false otherwise. */ @@ -355,7 +355,7 @@ /** Determines if the selected OUT endpoint has received new packet from the host. * - * \ingroup Group_EndpointPacketManagement_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX * * \return Boolean \c true if current endpoint is has received an OUT packet, \c false otherwise. */ @@ -363,7 +363,7 @@ /** Determines if the current CONTROL type endpoint has received a SETUP packet. * - * \ingroup Group_EndpointPacketManagement_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX * * \return Boolean \c true if the selected endpoint has received a SETUP packet, \c false otherwise. */ @@ -372,7 +372,7 @@ /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the * endpoint for the next packet. * - * \ingroup Group_EndpointPacketManagement_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX * * \note This is not applicable for non CONTROL type endpoints. */ @@ -381,14 +381,14 @@ /** 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_XMEGA + * \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_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX */ void Endpoint_ClearOUT(void); @@ -401,13 +401,13 @@ * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected * endpoint. * - * \ingroup Group_EndpointPacketManagement_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX */ void Endpoint_StallTransaction(void); /** Clears the STALL condition on the currently selected endpoint. * - * \ingroup Group_EndpointPacketManagement_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX */ ATTR_ALWAYS_INLINE static inline void Endpoint_ClearStall(void) @@ -417,7 +417,7 @@ /** Determines if the currently selected endpoint is stalled, \c false otherwise. * - * \ingroup Group_EndpointPacketManagement_XMEGA + * \ingroup Group_EndpointPacketManagement_AVRDX * * \return Boolean \c true if the currently selected endpoint is stalled, \c false otherwise. */ @@ -446,7 +446,7 @@ /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \return Next byte in the currently selected endpoint's FIFO buffer. */ @@ -454,7 +454,7 @@ /** Writes one byte to the currently selected endpoint's bank, for IN direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \param[in] Data Data to write into the the currently selected endpoint's FIFO buffer. */ @@ -462,7 +462,7 @@ /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX */ ATTR_ALWAYS_INLINE static inline void Endpoint_Discard_8(void) @@ -473,7 +473,7 @@ /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT * direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \return Next two bytes in the currently selected endpoint's FIFO buffer. */ @@ -489,7 +489,7 @@ /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT * direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \return Next two bytes in the currently selected endpoint's FIFO buffer. */ @@ -505,7 +505,7 @@ /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN * direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \param[in] Data Data to write to the currently selected endpoint's FIFO buffer. */ @@ -519,7 +519,7 @@ /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN * direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \param[in] Data Data to write to the currently selected endpoint's FIFO buffer. */ @@ -532,7 +532,7 @@ /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX */ ATTR_ALWAYS_INLINE static inline void Endpoint_Discard_16(void) @@ -544,7 +544,7 @@ /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT * direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \return Next four bytes in the currently selected endpoint's FIFO buffer. */ @@ -562,7 +562,7 @@ /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT * direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \return Next four bytes in the currently selected endpoint's FIFO buffer. */ @@ -580,7 +580,7 @@ /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN * direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \param[in] Data Data to write to the currently selected endpoint's FIFO buffer. */ @@ -596,7 +596,7 @@ /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN * direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX * * \param[in] Data Data to write to the currently selected endpoint's FIFO buffer. */ @@ -611,7 +611,7 @@ /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints. * - * \ingroup Group_EndpointPrimitiveRW_XMEGA + * \ingroup Group_EndpointPrimitiveRW_AVRDX */ ATTR_ALWAYS_INLINE static inline void Endpoint_Discard_32(void) @@ -672,7 +672,7 @@ * * \note This routine should not be called on CONTROL type endpoints. * - * \ingroup Group_EndpointRW_XMEGA + * \ingroup Group_EndpointRW_AVRDX * * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum. */ diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c index 6694d60cc..6afd8340e 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c @@ -29,7 +29,7 @@ */ #include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_USB_DRIVER #include "../USBMode.h" diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_AVR_Dx.c index 6694d60cc..6afd8340e 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_AVR_Dx.c @@ -29,7 +29,7 @@ */ #include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_USB_DRIVER #include "../USBMode.h" diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c index ce38ac33d..90e96f550 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c @@ -29,7 +29,7 @@ */ #include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_USB_DRIVER #define __INCLUDE_FROM_USB_CONTROLLER_C diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h index 4ded8495c..da813b563 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h @@ -29,24 +29,24 @@ */ /** \file - * \brief USB Controller definitions for the AVR XMEGA microcontrollers. - * \copydetails Group_USBManagement_XMEGA + * \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_XMEGA USB Interface Management (XMEGA) - * \brief USB Controller definitions for the AVR XMEGA microcontrollers. + * \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_XMEGA_H__ -#define __USBCONTROLLER_XMEGA_H__ +#ifndef __USBCONTROLLER_AVRDX_H__ +#define __USBCONTROLLER_AVRDX_H__ /* Includes: */ #include "../../../../Common/Common.h" diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c index 398708e98..890df91b6 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c @@ -29,7 +29,7 @@ */ #include "../../../../Common/Common.h" -#if (ARCH == ARCH_XMEGA) +#if (ARCH == ARCH_AVRDX) #define __INCLUDE_FROM_USB_DRIVER #include "../USBInterrupt.h" diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h index 2dc92afcd..72aaae64d 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h @@ -29,7 +29,7 @@ */ /** \file - * \brief USB Controller Interrupt definitions for the AVR XMEGA microcontrollers. + * \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. @@ -38,8 +38,8 @@ * dispatch header located in LUFA/Drivers/USB/USB.h. */ -#ifndef __USBINTERRUPT_XMEGA_H__ -#define __USBINTERRUPT_XMEGA_H__ +#ifndef __USBINTERRUPT_AVRDX_H__ +#define __USBINTERRUPT_AVRDX_H__ /* Includes: */ #include "../../../../Common/Common.h" diff --git a/LUFA/Platform/AVR_Dx/ClockManagement.h b/LUFA/Platform/AVR_Dx/ClockManagement.h index fe57e8c40..25750583c 100644 --- a/LUFA/Platform/AVR_Dx/ClockManagement.h +++ b/LUFA/Platform/AVR_Dx/ClockManagement.h @@ -29,45 +29,45 @@ */ /** \file - * \brief Module Clock Driver for the AVR USB XMEGA microcontrollers. + * \brief Module Clock Driver for the AVR Dx USB microcontrollers. * - * Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration + * 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_XMEGA - * \defgroup Group_PlatformDrivers_XMEGAClocks Clock Management Driver - LUFA/Platform/XMEGA/ClockManagement.h - * \brief Module Clock Driver for the AVR USB XMEGA microcontrollers. +/** \ingroup Group_PlatformDrivers_AVRDX + * \defgroup Group_PlatformDrivers_AVRDXClocks Clock Management Driver - LUFA/Platform/AVR_Dx/ClockManagement.h + * \brief Module Clock Driver for the AVR Dx USB microcontrollers. * - * \section Sec_PlatformDrivers_XMEGAClocks_Dependencies Module Source Dependencies + * \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_XMEGAClocks_ModDescription Module Description - * Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration + * \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 + * #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 - * XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU); - * XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL); + * 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 - * XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ); - * XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); + * AVRDXCLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ); + * AVRDXCLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); * } * \endcode * * @{ */ -#ifndef _XMEGA_CLOCK_MANAGEMENT_H_ -#define _XMEGA_CLOCK_MANAGEMENT_H_ +#ifndef _AVRDX_CLOCK_MANAGEMENT_H_ +#define _AVRDX_CLOCK_MANAGEMENT_H_ /* Includes: */ #include "../../Common/Common.h" @@ -80,7 +80,7 @@ /* Public Interface - May be used in end-application: */ /* Macros: */ /** Enum for the possible external oscillator frequency ranges. */ - enum XMEGA_Extern_OSC_ClockFrequency_t + enum AVRDX_Extern_OSC_ClockFrequency_t { EXOSC_FREQ_2MHZ_MAX = OSC_FRQRANGE_04TO2_gc, /**< External crystal oscillator equal to or slower than 2MHz. */ EXOSC_FREQ_9MHZ_MAX = OSC_FRQRANGE_2TO9_gc, /**< External crystal oscillator equal to or slower than 9MHz. */ @@ -89,7 +89,7 @@ }; /** Enum for the possible external oscillator startup times. */ - enum XMEGA_Extern_OSC_ClockStartup_t + enum AVRDX_Extern_OSC_ClockStartup_t { EXOSC_START_6CLK = OSC_XOSCSEL_EXTCLK_gc, /**< Wait 6 clock cycles before startup (external clock). */ EXOSC_START_32KCLK = OSC_XOSCSEL_32KHz_gc, /**< Wait 32K clock cycles before startup (32.768KHz crystal). */ @@ -99,7 +99,7 @@ }; /** Enum for the possible module clock sources. */ - enum XMEGA_System_ClockSource_t + enum AVRDX_System_ClockSource_t { CLOCK_SRC_INT_RC2MHZ = 0, /**< Clock sourced from the Internal 2MHz RC Oscillator clock. */ CLOCK_SRC_INT_RC32MHZ = 1, /**< Clock sourced from the Internal 32MHz RC Oscillator clock. */ @@ -109,7 +109,7 @@ }; /** Enum for the possible DFLL clock reference sources. */ - enum XMEGA_System_DFLLReference_t + enum AVRDX_System_DFLLReference_t { DFLL_REF_INT_RC32KHZ = 0, /**< Reference clock sourced from the Internal 32KHz RC Oscillator clock. */ DFLL_REF_EXT_RC32KHZ = 1, /**< Reference clock sourced from the External 32KHz RC Oscillator clock connected to TOSC pins. */ @@ -117,14 +117,14 @@ }; /* Inline Functions: */ - /** Write a value to a location protected by the XMEGA CCP protection mechanism. This function uses inline assembly to ensure that + /** 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 XMEGACLK_CCP_Write(volatile void* Address, const uint8_t Value) + 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 */ @@ -137,17 +137,17 @@ ); } - /** Starts the external oscillator of the XMEGA microcontroller, with the given options. This routine blocks until + /** 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 XMEGA_Extern_OSC_ClockFrequency_t. - * \param[in] Startup Startup time of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockStartup_t. + * \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 XMEGACLK_StartExternalOscillator(const uint8_t FreqRange, + static inline bool AVRDXCLK_StartExternalOscillator(const uint8_t FreqRange, const uint8_t Startup) ATTR_ALWAYS_INLINE; - static inline bool XMEGACLK_StartExternalOscillator(const uint8_t FreqRange, + static inline bool AVRDXCLK_StartExternalOscillator(const uint8_t FreqRange, const uint8_t Startup) { OSC.XOSCCTRL = (FreqRange | ((Startup == EXOSC_START_32KCLK) ? OSC_X32KLPM_bm : 0) | Startup); @@ -157,22 +157,22 @@ return true; } - /** Stops the external oscillator of the XMEGA microcontroller. */ + /** Stops the external oscillator of the AVR Dx microcontroller. */ ATTR_ALWAYS_INLINE - static inline void XMEGACLK_StopExternalOscillator(void) + static inline void AVRDXCLK_StopExternalOscillator(void) { OSC.CTRL &= ~OSC_XOSCEN_bm; } - /** Starts the given internal oscillator of the XMEGA microcontroller, with the given options. This routine blocks until + /** Starts the given internal oscillator of the AVR Dx microcontroller, with the given options. This routine blocks until * the oscillator is ready for use. * - * \param[in] Source Internal oscillator to start, a value from \ref XMEGA_System_ClockSource_t. + * \param[in] Source Internal oscillator to start, a value from \ref AVRDX_System_ClockSource_t. * * \return Boolean \c true if the internal oscillator was successfully started, \c false if invalid parameters specified. */ ATTR_ALWAYS_INLINE - static inline bool XMEGACLK_StartInternalOscillator(const uint8_t Source) + static inline bool AVRDXCLK_StartInternalOscillator(const uint8_t Source) { switch (Source) { @@ -193,14 +193,14 @@ } } - /** Stops the given internal oscillator of the XMEGA microcontroller. + /** Stops the given internal oscillator of the AVR Dx microcontroller. * - * \param[in] Source Internal oscillator to stop, a value from \ref XMEGA_System_ClockSource_t. + * \param[in] Source Internal oscillator to stop, a value from \ref AVRDX_System_ClockSource_t. * * \return Boolean \c true if the internal oscillator was successfully stopped, \c false if invalid parameters specified. */ ATTR_ALWAYS_INLINE - static inline bool XMEGACLK_StopInternalOscillator(const uint8_t Source) + static inline bool AVRDXCLK_StopInternalOscillator(const uint8_t Source) { switch (Source) { @@ -218,20 +218,20 @@ } } - /** Starts the PLL of the XMEGA microcontroller, with the given options. This routine blocks until the PLL is ready for use. + /** Starts the PLL of the AVR Dx microcontroller, with the given options. This routine blocks until the PLL is ready for use. * * \attention The output frequency must be equal to or greater than the source frequency. * - * \param[in] Source Clock source for the PLL, a value from \ref XMEGA_System_ClockSource_t. + * \param[in] Source Clock source for the PLL, a value from \ref AVRDX_System_ClockSource_t. * \param[in] SourceFreq Frequency of the PLL's clock source, in Hz. * \param[in] Frequency Target frequency of the PLL's output. * * \return Boolean \c true if the PLL was successfully started, \c false if invalid parameters specified. */ - static inline bool XMEGACLK_StartPLL(const uint8_t Source, + static inline bool AVRDXCLK_StartPLL(const uint8_t Source, const uint32_t SourceFreq, const uint32_t Frequency) ATTR_ALWAYS_INLINE; - static inline bool XMEGACLK_StartPLL(const uint8_t Source, + static inline bool AVRDXCLK_StartPLL(const uint8_t Source, const uint32_t SourceFreq, const uint32_t Frequency) { @@ -264,25 +264,25 @@ return true; } - /** Stops the PLL of the XMEGA microcontroller. */ + /** Stops the PLL of the AVR Dx microcontroller. */ ATTR_ALWAYS_INLINE - static inline void XMEGACLK_StopPLL(void) + static inline void AVRDXCLK_StopPLL(void) { OSC.CTRL &= ~OSC_PLLEN_bm; } - /** Starts the DFLL of the XMEGA microcontroller, with the given options. + /** Starts the DFLL of the AVR Dx microcontroller, with the given options. * - * \param[in] Source RC Clock source for the DFLL, a value from \ref XMEGA_System_ClockSource_t. - * \param[in] Reference Reference clock source for the DFLL, an value from \ref XMEGA_System_DFLLReference_t. + * \param[in] Source RC Clock source for the DFLL, a value from \ref AVRDX_System_ClockSource_t. + * \param[in] Reference Reference clock source for the DFLL, an value from \ref AVRDX_System_DFLLReference_t. * \param[in] Frequency Target frequency of the DFLL's output. * * \return Boolean \c true if the DFLL was successfully started, \c false if invalid parameters specified. */ - static inline bool XMEGACLK_StartDFLL(const uint8_t Source, + static inline bool AVRDXCLK_StartDFLL(const uint8_t Source, const uint8_t Reference, const uint32_t Frequency) ATTR_ALWAYS_INLINE; - static inline bool XMEGACLK_StartDFLL(const uint8_t Source, + static inline bool AVRDXCLK_StartDFLL(const uint8_t Source, const uint8_t Reference, const uint32_t Frequency) { @@ -318,14 +318,14 @@ return true; } - /** Stops the given DFLL of the XMEGA microcontroller. + /** Stops the given DFLL of the AVR Dx microcontroller. * - * \param[in] Source RC Clock source for the DFLL to be stopped, a value from \ref XMEGA_System_ClockSource_t. + * \param[in] Source RC Clock source for the DFLL to be stopped, a value from \ref AVRDX_System_ClockSource_t. * * \return Boolean \c true if the DFLL was successfully stopped, \c false if invalid parameters specified. */ ATTR_ALWAYS_INLINE - static inline bool XMEGACLK_StopDFLL(const uint8_t Source) + static inline bool AVRDXCLK_StopDFLL(const uint8_t Source) { switch (Source) { @@ -345,12 +345,12 @@ /** Sets the clock source for the main microcontroller core. The given clock source should be configured * and ready for use before this function is called. * - * \param[in] Source Clock source for the CPU core, a value from \ref XMEGA_System_ClockSource_t. + * \param[in] 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 XMEGACLK_SetCPUClockSource(const uint8_t Source) + static inline bool AVRDXCLK_SetCPUClockSource(const uint8_t Source) { uint8_t ClockSourceMask = 0; @@ -378,7 +378,7 @@ uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); GlobalInterruptDisable(); - XMEGACLK_CCP_Write(&CLK.CTRL, ClockSourceMask); + AVRDXCLK_CCP_Write(&CLK.CTRL, ClockSourceMask); SetGlobalInterruptMask(CurrentGlobalInt); From 753ce779ef2094c349e83a3d4c76f14406efeb07 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 13:30:40 +0100 Subject: [PATCH 04/30] Adding intitial ARCH == ARCH_AVRDX --- BuildTests/ModuleTest/Modules.h | 5 +++ .../DeviceTemplate/DeviceApplication.c | 12 +++++++ LUFA/CodeTemplates/LUFAConfig.h | 33 +++++++++++++++++++ LUFA/Common/ArchitectureSpecific.h | 2 +- LUFA/Common/Architectures.h | 3 ++ LUFA/Common/Common.h | 20 ++++------- LUFA/Drivers/Peripheral/SPI.h | 2 ++ LUFA/Drivers/Peripheral/Serial.h | 2 ++ LUFA/Drivers/Peripheral/SerialSPI.h | 2 ++ LUFA/Drivers/Peripheral/TWI.h | 2 ++ LUFA/Drivers/USB/Core/Device.h | 2 ++ LUFA/Drivers/USB/Core/Endpoint.h | 2 ++ LUFA/Drivers/USB/Core/EndpointStream.h | 2 ++ LUFA/Drivers/USB/Core/StdDescriptors.h | 2 +- LUFA/Drivers/USB/Core/USBController.h | 2 ++ LUFA/Drivers/USB/Core/USBInterrupt.h | 2 ++ LUFA/Platform/Platform.h | 2 ++ 17 files changed, 81 insertions(+), 16 deletions(-) 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/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c b/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c index 0f90e55bd..5872d0593 100644 --- a/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c +++ b/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c @@ -76,6 +76,18 @@ void SetupHardware(void) PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; + /* Hardware Initialization */ + USB_Init(USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH); + + #elif (ARCH == ARCH_AVRDX) + /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz 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 48MHz 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); + /* Hardware Initialization */ USB_Init(USB_OPT_RC32MCLKSRC | 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/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/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h index 3c1513d10..6a5126186 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 "AVR_Dx/SPI_AVR_Dx.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..6a3d3fb30 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 "AVR_Dx/Serial_AVR_Dx.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..9c05f6d66 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 "AVR_Dx/SerialSPI_AVR_Dx.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..e917c3e14 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 "AVR_Dx/TWI_AVR_Dx.h" #else #error The TWI peripheral driver is not currently available for your selected architecture. #endif diff --git a/LUFA/Drivers/USB/Core/Device.h b/LUFA/Drivers/USB/Core/Device.h index 1a9f989a4..09d3c0733 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 "AVR_Dx/Device_AVR_Dx.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..518d2b34a 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 "AVR_Dx/Endpoint_AVR_Dx.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..c5c13d64f 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 "AVR_Dx/EndpointStream_AVR_Dx.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..064a956e3 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 "AVR_Dx/USBController_AVR_Dx.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..373796449 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 "AVR_Dx/USBInterrupt_AVR_Dx.h" #endif /* Disable C linkage for C++ Compilers: */ diff --git a/LUFA/Platform/Platform.h b/LUFA/Platform/Platform.h index fb8398f98..fcc46269e 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 "AVR_Dx/ClockManagement.h" #endif #endif From 4b55b46ee874260076de2b7d4d97cc4956f62857 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 14:42:09 +0100 Subject: [PATCH 05/30] Clock Management register updates for Dx --- .../DeviceTemplate/DeviceApplication.c | 10 +- LUFA/Platform/AVR_Dx/ClockManagement.h | 253 ++++-------------- 2 files changed, 58 insertions(+), 205 deletions(-) diff --git a/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c b/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c index 5872d0593..c8c028f32 100644 --- a/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c +++ b/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c @@ -80,13 +80,9 @@ void SetupHardware(void) USB_Init(USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH); #elif (ARCH == ARCH_AVRDX) - /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz 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 48MHz 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); + /* 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_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH); diff --git a/LUFA/Platform/AVR_Dx/ClockManagement.h b/LUFA/Platform/AVR_Dx/ClockManagement.h index 25750583c..7d83cb5f4 100644 --- a/LUFA/Platform/AVR_Dx/ClockManagement.h +++ b/LUFA/Platform/AVR_Dx/ClockManagement.h @@ -82,38 +82,38 @@ /** Enum for the possible external oscillator frequency ranges. */ enum AVRDX_Extern_OSC_ClockFrequency_t { - EXOSC_FREQ_2MHZ_MAX = OSC_FRQRANGE_04TO2_gc, /**< External crystal oscillator equal to or slower than 2MHz. */ - EXOSC_FREQ_9MHZ_MAX = OSC_FRQRANGE_2TO9_gc, /**< External crystal oscillator equal to or slower than 9MHz. */ - EXOSC_FREQ_12MHZ_MAX = OSC_FRQRANGE_9TO12_gc, /**< External crystal oscillator equal to or slower than 12MHz. */ - EXOSC_FREQ_16MHZ_MAX = OSC_FRQRANGE_12TO16_gc, /**< External crystal oscillator equal to or slower than 16MHz. */ + 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 external oscillator startup times. */ + /** Enum for the possible high-frequency external oscillator startup times. */ enum AVRDX_Extern_OSC_ClockStartup_t { - EXOSC_START_6CLK = OSC_XOSCSEL_EXTCLK_gc, /**< Wait 6 clock cycles before startup (external clock). */ - EXOSC_START_32KCLK = OSC_XOSCSEL_32KHz_gc, /**< Wait 32K clock cycles before startup (32.768KHz crystal). */ - EXOSC_START_256CLK = OSC_XOSCSEL_XTAL_256CLK_gc, /**< Wait 256 clock cycles before startup. */ - EXOSC_START_1KCLK = OSC_XOSCSEL_XTAL_1KCLK_gc, /**< Wait 1K clock cycles before startup. */ - EXOSC_START_16KCLK = OSC_XOSCSEL_XTAL_16KCLK_gc, /**< Wait 16K clock cycles before startup. */ + 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_RC2MHZ = 0, /**< Clock sourced from the Internal 2MHz RC Oscillator clock. */ - CLOCK_SRC_INT_RC32MHZ = 1, /**< Clock sourced from the Internal 32MHz RC Oscillator clock. */ - CLOCK_SRC_INT_RC32KHZ = 2, /**< Clock sourced from the Internal 32KHz RC Oscillator clock. */ - CLOCK_SRC_XOSC = 3, /**< Clock sourced from the External Oscillator clock. */ - CLOCK_SRC_PLL = 4, /**< Clock sourced from the Internal PLL clock. */ + 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 DFLL clock reference sources. */ - enum AVRDX_System_DFLLReference_t + /** Enum for the possible OSCHF Autotune sources. */ + enum AVRDX_System_OSCHFAutotune_t { - DFLL_REF_INT_RC32KHZ = 0, /**< Reference clock sourced from the Internal 32KHz RC Oscillator clock. */ - DFLL_REF_EXT_RC32KHZ = 1, /**< Reference clock sourced from the External 32KHz RC Oscillator clock connected to TOSC pins. */ - DFLL_REF_INT_USBSOF = 2, /**< Reference clock sourced from the USB Start Of Frame packets. */ + 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: */ @@ -150,10 +150,9 @@ static inline bool AVRDXCLK_StartExternalOscillator(const uint8_t FreqRange, const uint8_t Startup) { - OSC.XOSCCTRL = (FreqRange | ((Startup == EXOSC_START_32KCLK) ? OSC_X32KLPM_bm : 0) | Startup); - OSC.CTRL |= OSC_XOSCEN_bm; + AVRDXCLK_CCP_Write(&CLKCTRL.XOSCHFCTRLA, FreqRange | Startup | CLKCTRL_ENABLE_bm); - while (!(OSC.STATUS & OSC_XOSCRDY_bm)); + while (!(CLKCTRL.MCLKSTATUS & CLKCTRL_EXTS_bm)); return true; } @@ -161,187 +160,47 @@ ATTR_ALWAYS_INLINE static inline void AVRDXCLK_StopExternalOscillator(void) { - OSC.CTRL &= ~OSC_XOSCEN_bm; + AVRDXCLK_CCP_Write(&CLKCTRL.XOSCHFCTRLA, 0); } - /** Starts the given internal oscillator of the AVR Dx microcontroller, with the given options. This routine blocks until - * the oscillator is ready for use. - * - * \param[in] Source Internal oscillator to start, a value from \ref AVRDX_System_ClockSource_t. - * - * \return Boolean \c true if the internal oscillator was successfully started, \c false if invalid parameters specified. - */ - ATTR_ALWAYS_INLINE - static inline bool AVRDXCLK_StartInternalOscillator(const uint8_t Source) - { - switch (Source) - { - case CLOCK_SRC_INT_RC2MHZ: - OSC.CTRL |= OSC_RC2MEN_bm; - while (!(OSC.STATUS & OSC_RC2MRDY_bm)); - return true; - case CLOCK_SRC_INT_RC32MHZ: - OSC.CTRL |= OSC_RC32MEN_bm; - while (!(OSC.STATUS & OSC_RC32MRDY_bm)); - return true; - case CLOCK_SRC_INT_RC32KHZ: - OSC.CTRL |= OSC_RC32KEN_bm; - while (!(OSC.STATUS & OSC_RC32KRDY_bm)); - return true; - default: - return false; - } - } - - /** Stops the given internal oscillator of the AVR Dx microcontroller. - * - * \param[in] Source Internal oscillator to stop, a value from \ref AVRDX_System_ClockSource_t. - * - * \return Boolean \c true if the internal oscillator was successfully stopped, \c false if invalid parameters specified. - */ - ATTR_ALWAYS_INLINE - static inline bool AVRDXCLK_StopInternalOscillator(const uint8_t Source) - { - switch (Source) - { - case CLOCK_SRC_INT_RC2MHZ: - OSC.CTRL &= ~OSC_RC2MEN_bm; - return true; - case CLOCK_SRC_INT_RC32MHZ: - OSC.CTRL &= ~OSC_RC32MEN_bm; - return true; - case CLOCK_SRC_INT_RC32KHZ: - OSC.CTRL &= ~OSC_RC32KEN_bm; - return true; - default: - return false; - } - } - - /** Starts the PLL of the AVR Dx microcontroller, with the given options. This routine blocks until the PLL is ready for use. + /** 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 the source frequency. + * \attention The output frequency must be equal to or greater than 12 MHz. * - * \param[in] Source Clock source for the PLL, a value from \ref AVRDX_System_ClockSource_t. - * \param[in] SourceFreq Frequency of the PLL's clock source, in Hz. - * \param[in] Frequency Target frequency of the PLL's output. + * \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 PLL was successfully started, \c false if invalid parameters specified. + * \return Boolean \c true if the OSCHF was successfully started, \c false if invalid parameters specified. */ - static inline bool AVRDXCLK_StartPLL(const uint8_t Source, - const uint32_t SourceFreq, - const uint32_t Frequency) ATTR_ALWAYS_INLINE; - static inline bool AVRDXCLK_StartPLL(const uint8_t Source, - const uint32_t SourceFreq, - const uint32_t Frequency) + 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 MulFactor = (Frequency / SourceFreq); - - if (SourceFreq > Frequency) - return false; - - if (MulFactor > 31) - return false; - - switch (Source) + uint8_t ClockConfigMask = Autotune; + switch (Frequency) { - case CLOCK_SRC_INT_RC2MHZ: - OSC.PLLCTRL = (OSC_PLLSRC_RC2M_gc | MulFactor); - break; - case CLOCK_SRC_INT_RC32MHZ: - OSC.PLLCTRL = (OSC_PLLSRC_RC32M_gc | MulFactor); + case 12000000ul: + ClockConfigMask |= CLKCTRL_FRQSEL_12M_gc; break; - case CLOCK_SRC_XOSC: - OSC.PLLCTRL = (OSC_PLLSRC_XOSC_gc | MulFactor); + case 16000000ul: + ClockConfigMask |= CLKCTRL_FRQSEL_16M_gc; break; - default: - return false; - } - - OSC.CTRL |= OSC_PLLEN_bm; - - while (!(OSC.STATUS & OSC_PLLRDY_bm)); - return true; - } - - /** Stops the PLL of the AVR Dx microcontroller. */ - ATTR_ALWAYS_INLINE - static inline void AVRDXCLK_StopPLL(void) - { - OSC.CTRL &= ~OSC_PLLEN_bm; - } - - /** Starts the DFLL of the AVR Dx microcontroller, with the given options. - * - * \param[in] Source RC Clock source for the DFLL, a value from \ref AVRDX_System_ClockSource_t. - * \param[in] Reference Reference clock source for the DFLL, an value from \ref AVRDX_System_DFLLReference_t. - * \param[in] Frequency Target frequency of the DFLL's output. - * - * \return Boolean \c true if the DFLL was successfully started, \c false if invalid parameters specified. - */ - static inline bool AVRDXCLK_StartDFLL(const uint8_t Source, - const uint8_t Reference, - const uint32_t Frequency) ATTR_ALWAYS_INLINE; - static inline bool AVRDXCLK_StartDFLL(const uint8_t Source, - const uint8_t Reference, - const uint32_t Frequency) - { - uint16_t DFLLCompare = (Frequency / 1024); - - switch (Source) - { - case CLOCK_SRC_INT_RC2MHZ: - OSC.DFLLCTRL |= (Reference << OSC_RC2MCREF_bp); - DFLLRC2M.COMP1 = (DFLLCompare & 0xFF); - DFLLRC2M.COMP2 = (DFLLCompare >> 8); - DFLLRC2M.CTRL = DFLL_ENABLE_bm; + case 20000000ul: + ClockConfigMask |= CLKCTRL_FRQSEL_20M_gc; break; - case CLOCK_SRC_INT_RC32MHZ: - OSC.DFLLCTRL |= (Reference << OSC_RC32MCREF_gp); - DFLLRC32M.COMP1 = (DFLLCompare & 0xFF); - DFLLRC32M.COMP2 = (DFLLCompare >> 8); - - if (Reference == DFLL_REF_INT_USBSOF) - { - NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; - DFLLRC32M.CALA = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBRCOSCA)); - DFLLRC32M.CALB = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBRCOSC)); - NVM.CMD = 0; - } - - DFLLRC32M.CTRL = DFLL_ENABLE_bm; + case 24000000ul: + ClockConfigMask |= CLKCTRL_FRQSEL_24M_gc; break; default: return false; } - return true; - } - - /** Stops the given DFLL of the AVR Dx microcontroller. - * - * \param[in] Source RC Clock source for the DFLL to be stopped, a value from \ref AVRDX_System_ClockSource_t. - * - * \return Boolean \c true if the DFLL was successfully stopped, \c false if invalid parameters specified. - */ - ATTR_ALWAYS_INLINE - static inline bool AVRDXCLK_StopDFLL(const uint8_t Source) - { - switch (Source) - { - case CLOCK_SRC_INT_RC2MHZ: - DFLLRC2M.CTRL = 0; - break; - case CLOCK_SRC_INT_RC32MHZ: - DFLLRC32M.CTRL = 0; - 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. * @@ -356,20 +215,18 @@ switch (Source) { - case CLOCK_SRC_INT_RC2MHZ: - ClockSourceMask = CLK_SCLKSEL_RC2M_gc; - break; - case CLOCK_SRC_INT_RC32MHZ: - ClockSourceMask = CLK_SCLKSEL_RC32M_gc; + case CLOCK_SRC_INT_OSCHF: + ClockSourceMask = CLKCTRL_CLKSEL_OSCHF_gc; break; - case CLOCK_SRC_INT_RC32KHZ: - ClockSourceMask = CLK_SCLKSEL_RC32K_gc; + case CLOCK_SRC_INT_32KHZ: + ClockSourceMask = CLKCTRL_CLKSEL_OSC32K_gc; break; - case CLOCK_SRC_XOSC: - ClockSourceMask = CLK_SCLKSEL_XOSC_gc; + case CLOCK_SRC_EXT_CLK: + case CLOCK_SRC_EXT_OSC: + ClockSourceMask = CLKCTRL_CLKSEL_EXTCLK_gc; break; - case CLOCK_SRC_PLL: - ClockSourceMask = CLK_SCLKSEL_PLL_gc; + case CLOCK_SRC_EXT_32KHZ: + ClockSourceMask = CLKCTRL_CLKSEL_XOSC32K_gc; break; default: return false; @@ -378,12 +235,12 @@ uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); GlobalInterruptDisable(); - AVRDXCLK_CCP_Write(&CLK.CTRL, ClockSourceMask); + AVRDXCLK_CCP_Write(&CLKCTRL.MCLKCTRLA, ClockSourceMask); SetGlobalInterruptMask(CurrentGlobalInt); - Delay_MS(1); - return (CLK.CTRL == ClockSourceMask); + while (CLKCTRL.MCLKSTATUS & CLKCTRL_SOSC_bm); + return ((CLKCTRL.MCLKCTRLA & CLKCTRL_CLKSEL_gm) == ClockSourceMask); } /* Disable C linkage for C++ Compilers: */ From e90c7816790be25f720d573151d516429ef8be3c Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 14:43:35 +0100 Subject: [PATCH 06/30] USB Intterrupts updated for Dx --- .../USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c | 10 +++---- .../USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h | 28 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c index 890df91b6..d56fbf732 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c @@ -36,17 +36,17 @@ void USB_INT_DisableAllInterrupts(void) { - USB.INTCTRLA &= USB_INTLVL_gm; - USB.INTCTRLB = 0; + USB0.INTCTRLA = 0; + USB0.INTCTRLB = 0; } void USB_INT_ClearAllInterrupts(void) { - USB.INTFLAGSACLR = 0xFF; - USB.INTFLAGSBCLR = 0xFF; + USB0.INTFLAGSA = 0xFF; + USB0.INTFLAGSB = 0xFF; } -ISR(USB_BUSEVENT_vect) +ISR(USB0_BUSEVENT_vect) { #if !defined(NO_SOF_EVENTS) if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI)) diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h index 72aaae64d..4cdaf6848 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h @@ -73,10 +73,10 @@ switch (Interrupt) { case USB_INT_BUSEVENTI: - USB.INTCTRLA |= USB_BUSEVIE_bm; + USB0.INTCTRLA |= (USB_SUSPEND_bm | USB_RESUME_bm | USB_RESET_bm); break; case USB_INT_SOFI: - USB.INTCTRLA |= USB_SOFIE_bm; + USB0.INTCTRLA |= USB_SOF_bm; break; default: break; @@ -89,10 +89,10 @@ switch (Interrupt) { case USB_INT_BUSEVENTI: - USB.INTCTRLA &= ~USB_BUSEVIE_bm; + USB0.INTCTRLA &= ~(USB_SUSPEND_bm | USB_RESUME_bm | USB_RESET_bm); break; case USB_INT_SOFI: - USB.INTCTRLA &= ~USB_SOFIE_bm; + USB0.INTCTRLA &= ~USB_SOF_bm; break; default: break; @@ -105,16 +105,16 @@ switch (Interrupt) { case USB_INT_BUSEVENTI_Suspend: - USB.INTFLAGSACLR = USB_SUSPENDIF_bm; + USB0.INTFLAGSA = USB_SUSPEND_bm; break; case USB_INT_BUSEVENTI_Resume: - USB.INTFLAGSACLR = USB_RESUMEIF_bm; + USB0.INTFLAGSA = USB_RESUME_bm; break; case USB_INT_BUSEVENTI_Reset: - USB.INTFLAGSACLR = USB_RSTIF_bm; + USB0.INTFLAGSA = USB_RESET_bm; break; case USB_INT_SOFI: - USB.INTFLAGSACLR = USB_SOFIF_bm; + USB0.INTFLAGSA = USB_SOF_bm; break; default: break; @@ -127,9 +127,9 @@ switch (Interrupt) { case USB_INT_BUSEVENTI: - return ((USB.INTCTRLA & USB_BUSEVIE_bm) ? true : false); + return ((USB0.INTCTRLA & (USB_SUSPEND_bm | USB_RESUME_bm | USB_RESET_bm)) ? true : false); case USB_INT_SOFI: - return ((USB.INTCTRLA & USB_SOFIE_bm) ? true : false); + return ((USB0.INTCTRLA & USB_SOF_bm) ? true : false); default: return false; } @@ -141,13 +141,13 @@ switch (Interrupt) { case USB_INT_BUSEVENTI_Suspend: - return ((USB.INTFLAGSACLR & USB_SUSPENDIF_bm) ? true : false); + return ((USB0.INTFLAGSA & USB_SUSPEND_bm) ? true : false); case USB_INT_BUSEVENTI_Resume: - return ((USB.INTFLAGSACLR & USB_RESUMEIF_bm) ? true : false); + return ((USB0.INTFLAGSA & USB_RESUME_bm) ? true : false); case USB_INT_BUSEVENTI_Reset: - return ((USB.INTFLAGSACLR & USB_RSTIF_bm) ? true : false); + return ((USB0.INTFLAGSA & USB_RESET_bm) ? true : false); case USB_INT_SOFI: - return ((USB.INTFLAGSACLR & USB_SOFIF_bm) ? true : false); + return ((USB0.INTFLAGSA & USB_SOF_bm) ? true : false); default: return false; } From 38dbce3dd9f5051876f458f3f47e27bf2146b7c0 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 14:59:26 +0100 Subject: [PATCH 07/30] Updated the USBController for Dx --- .../USB/Core/AVR_Dx/USBController_AVR_Dx.c | 47 +++---------------- .../USB/Core/AVR_Dx/USBController_AVR_Dx.h | 38 +++++++-------- 2 files changed, 24 insertions(+), 61 deletions(-) diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c index 90e96f550..e79ac9d22 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c @@ -69,28 +69,20 @@ void USB_Init( uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); GlobalInterruptDisable(); - NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; - USB.CAL0 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL0)); - USB.CAL1 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL1)); - NVM.CMD = NVM_CMD_NO_OPERATION_gc; - /* Ugly workaround to ensure an aligned table, since __BIGGEST_ALIGNMENT__ == 1 for the 8-bit AVR-GCC toolchain */ - USB.EPPTR = ((intptr_t)&USB_EndpointTable[1] & ~(1 << 0)); - USB.CTRLA = (USB_STFRNUM_bm | ((ENDPOINT_TOTAL_ENDPOINTS - 1) << USB_MAXEP_gp)); + USB0.EPPTR = ((intptr_t)&USB_EndpointTable[1] & ~(1 << 0)); + USB0.CTRLA = (USB_STFRNUM_bm | ((ENDPOINT_TOTAL_ENDPOINTS - 1) << USB_MAXEP_gp)); if ((USB_Options & USB_OPT_BUSEVENT_PRIHIGH) == USB_OPT_BUSEVENT_PRIHIGH) - USB.INTCTRLA = (3 << USB_INTLVL_gp); - else if ((USB_Options & USB_OPT_BUSEVENT_PRIMED) == USB_OPT_BUSEVENT_PRIMED) - USB.INTCTRLA = (2 << USB_INTLVL_gp); + CPUINT.LVL1VEC = USB0_BUSEVENT_vect_num; + + if ((USB_Options & USB_OPT_USBVREG_ENABLE) == USB_OPT_USBVREG_ENABLE) + SYSCFG.VUSBCTRL = SYSCFG_USBVREG_ENABLE_gc; else - USB.INTCTRLA = (1 << USB_INTLVL_gp); + SYSCFG.VUSBCTRL = SYSCFG_USBVREG_DISABLE_gc; SetGlobalInterruptMask(CurrentGlobalInt); - #if defined(USB_CAN_BE_BOTH) - USB_CurrentMode = Mode; - #endif - USB_IsInitialized = true; USB_ResetInterface(); @@ -109,31 +101,6 @@ void USB_Disable(void) void USB_ResetInterface(void) { - uint8_t PrescalerNeeded; - - #if defined(USB_DEVICE_OPT_FULLSPEED) - if (USB_Options & USB_DEVICE_OPT_LOWSPEED) - PrescalerNeeded = F_USB / 6000000; - else - PrescalerNeeded = F_USB / 48000000; - #else - PrescalerNeeded = F_USB / 6000000; - #endif - - uint8_t DividerIndex = 0; - while (PrescalerNeeded > 0) - { - DividerIndex++; - PrescalerNeeded >>= 1; - } - - CLK.USBCTRL = (DividerIndex - 1) << CLK_USBPSDIV_gp; - - if (USB_Options & USB_OPT_PLLCLKSRC) - CLK.USBCTRL |= (CLK_USBSRC_PLL_gc | CLK_USBSEN_bm); - else - CLK.USBCTRL |= (CLK_USBSRC_RC32M_gc | CLK_USBSEN_bm); - USB_Device_SetDeviceAddress(0); USB_INT_DisableAllInterrupts(); diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h index da813b563..bc73b0a5b 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h @@ -97,12 +97,12 @@ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif - #if !defined(F_USB) - #error F_USB is not defined. You must define F_USB to the frequency of the unprescaled USB controller clock in your project makefile. + #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_USB % 6000000) || (F_USB < 6000000)) - #error Invalid F_USB specified. F_USB must be a multiple of 6MHz for USB Low Speed operation, and a multiple of 48MHz for Full Speed operation. + #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: */ @@ -112,23 +112,19 @@ /** 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 << 2) | (0 << 1)) - - /** Sets the USB bus interrupt priority level to be medium priority. The USB bus interrupt is used for Start of Frame events, bus suspend - * and resume events, bus reset events and other events related to the management of the USB bus. - */ - #define USB_OPT_BUSEVENT_PRIMED ((0 << 2) | (1 << 1)) + #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 << 2) | (0 << 1)) + #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) - /** Sets the USB controller to source its clock from the internal RC 32MHz clock, once it has been DFLL calibrated to 48MHz. */ - #define USB_OPT_RC32MCLKSRC (0 << 3) + /** Enables the internal 3.3V regulator for the VUSB pin. The VCC must be above ~4V */ + #define USB_OPT_USBVREG_ENABLE (1 << 2) - /** Sets the USB controller to source its clock from the internal PLL. */ - #define USB_OPT_PLLCLKSRC (1 << 3) /**@}*/ #if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__) @@ -150,7 +146,7 @@ ATTR_ALWAYS_INLINE static inline void USB_Detach(void) { - USB.CTRLB &= ~USB_ATTACH_bm; + USB0.CTRLB &= ~USB_ATTACH_bm; } /** Attaches the device to the USB bus. This announces the device's presence to any attached @@ -164,7 +160,7 @@ ATTR_ALWAYS_INLINE static inline void USB_Attach(void) { - USB.CTRLB |= USB_ATTACH_bm; + USB0.CTRLB |= USB_ATTACH_bm; } /* Function Prototypes: */ @@ -284,20 +280,20 @@ ATTR_ALWAYS_INLINE static inline void USB_Controller_Enable(void) { - USB.CTRLA |= USB_ENABLE_bm; + USB0.CTRLA |= USB_ENABLE_bm; } ATTR_ALWAYS_INLINE static inline void USB_Controller_Disable(void) { - USB.CTRLA &= ~USB_ENABLE_bm; + USB0.CTRLA &= ~USB_ENABLE_bm; } ATTR_ALWAYS_INLINE static inline void USB_Controller_Reset(void) { - USB.CTRLA &= ~USB_ENABLE_bm; - USB.CTRLA |= USB_ENABLE_bm; + USB0.CTRLA &= ~USB_ENABLE_bm; + USB0.CTRLA |= USB_ENABLE_bm; } #endif From 937179d17f9b596779c412a795c5528cd86f1ad2 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 15:44:55 +0100 Subject: [PATCH 08/30] Device updated for Dx --- LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c | 2 +- LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h | 59 ++++---------------- 2 files changed, 11 insertions(+), 50 deletions(-) diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c index a6bf8a362..ea40ff823 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c @@ -40,7 +40,7 @@ void USB_Device_SendRemoteWakeup(void) { - USB.CTRLB |= USB_RWAKEUP_bm; + USB0.CTRLB |= USB_URESUME_bm; } #endif diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h index 33e48dc8c..8bc22674c 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h @@ -79,27 +79,6 @@ /* Public Interface - May be used in end-application: */ /* Macros: */ - /** \name USB Device Mode Option Masks */ - /**@{*/ - /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the - * USB interface should be initialized in low speed (1.5Mb/s) mode. - * - * \note Low Speed mode is not available on all USB AVR models. - * \n - * - * \note Restrictions apply on the number, size and type of endpoints which can be used - * when running in low speed mode - refer to the USB 2.0 specification. - */ - #define USB_DEVICE_OPT_LOWSPEED (1 << 0) - - #if (F_USB > 6000000) - /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the - * USB interface should be initialized in full speed (12Mb/s) mode. - */ - #define USB_DEVICE_OPT_FULLSPEED (0 << 0) - #endif - /**@}*/ - #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 @@ -117,12 +96,12 @@ /** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller * model. */ - #define INTERNAL_SERIAL_LENGTH_BITS (8 * (1 + (offsetof(NVM_PROD_SIGNATURES_t, COORDY1) - offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0)))) + #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 offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) + #define INTERNAL_SERIAL_START_ADDRESS &SIGROW.SERNUM0 #else #undef USE_INTERNAL_SERIAL #define USE_INTERNAL_SERIAL NO_DESCRIPTOR @@ -162,7 +141,7 @@ ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT static inline uint16_t USB_Device_GetFrameNumber(void) { - return ((USB_EndpointTable_t*)USB.EPPTR)->FrameNum; + return ((USB_EndpointTable_t*)USB0.EPPTR)->FrameNum; } #if !defined(NO_SOF_EVENTS) @@ -175,7 +154,7 @@ ATTR_ALWAYS_INLINE static inline void USB_Device_EnableSOFEvents(void) { - USB.INTCTRLA |= USB_SOFIE_bm; + USB0.INTCTRLA |= USB_SOF_bm; } /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the @@ -186,43 +165,29 @@ ATTR_ALWAYS_INLINE static inline void USB_Device_DisableSOFEvents(void) { - USB.INTCTRLA &= ~USB_SOFIE_bm; + 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_SetLowSpeed(void) - { - USB.CTRLA &= ~USB_SPEED_bm; - } - - ATTR_ALWAYS_INLINE - static inline void USB_Device_SetFullSpeed(void) - { - USB.CTRLA |= USB_SPEED_bm; - } - ATTR_ALWAYS_INLINE static inline void USB_Device_SetDeviceAddress(const uint8_t Address) { - (void)Address; - - /* No implementation for AVR Dx architecture */ + USB0.ADDR = Address; } ATTR_ALWAYS_INLINE static inline void USB_Device_EnableDeviceAddress(const uint8_t Address) { - USB.ADDR = Address; + USB0.ADDR = Address; } ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT static inline bool USB_Device_IsAddressSet(void) { - return ((USB.ADDR != 0) ? true : false); + return ((USB0.ADDR != 0) ? true : false); } ATTR_NON_NULL_PTR_ARG(1) @@ -231,15 +196,11 @@ uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); GlobalInterruptDisable(); - uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS; + uint8_t* SigReadAddress = INTERNAL_SERIAL_START_ADDRESS; for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++) { - uint8_t SerialByte; - - NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; - SerialByte = pgm_read_byte(SigReadAddress); - NVM.CMD = 0; + uint8_t SerialByte = *SigReadAddress; if (SerialCharNum & 0x01) { From d022ad5761bca5f1c600ac04f723cb03934c8e49 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 16:28:35 +0100 Subject: [PATCH 09/30] Endpoint updated for Dx --- .../Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c | 32 +++++----- .../Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h | 59 +++++++++++++++---- 2 files changed, 64 insertions(+), 27 deletions(-) diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c index 82d902be8..e0fd6641f 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c @@ -52,14 +52,14 @@ bool Endpoint_IsINReady(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); - return ((USB_Endpoint_SelectedHandle->STATUS & USB_EP_BUSNACK0_bm) ? true : false); + return ((USB_Endpoint_GetStatus() & USB_BUSNAK_bm) ? true : false); } bool Endpoint_IsOUTReceived(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); - if (USB_Endpoint_SelectedHandle->STATUS & USB_EP_TRNCOMPL0_bm) + if (USB_Endpoint_GetStatus() & USB_TRNCOMPL_bm) { USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; return true; @@ -72,7 +72,7 @@ bool Endpoint_IsSETUPReceived(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); - if (USB_Endpoint_SelectedHandle->STATUS & USB_EP_SETUP_bm) + if (USB_Endpoint_GetStatus() & USB_SETUP_bm) { USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; return true; @@ -84,36 +84,36 @@ bool Endpoint_IsSETUPReceived(void) void Endpoint_ClearSETUP(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); - USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_SETUP_bm | USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); - USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; + USB_Endpoint_ClearStatus(USB_SETUP_bm | USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); + USB_Endpoint_SetStatus(USB_TOGGLE_bm); USB_Endpoint_SelectedFIFO->Position = 0; Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); - USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; + USB_Endpoint_SetStatus(USB_TOGGLE_bm); USB_Endpoint_SelectedFIFO->Position = 0; } void Endpoint_ClearIN(void) { USB_Endpoint_SelectedHandle->CNT = USB_Endpoint_SelectedFIFO->Position; - USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); + USB_Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); USB_Endpoint_SelectedFIFO->Position = 0; } void Endpoint_ClearOUT(void) { - USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); + USB_Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); USB_Endpoint_SelectedFIFO->Position = 0; } void Endpoint_StallTransaction(void) { - USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_bm; + USB_Endpoint_SelectedHandle->CTRL |= USB_DOSTALL_bm; - if ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_TYPE_gm) == USB_EP_TYPE_CONTROL_gc) + 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_EP_STALL_bm; + USB_Endpoint_SelectedHandle->CTRL |= USB_DOSTALL_bm; } } @@ -134,7 +134,7 @@ void Endpoint_SelectEndpoint(const uint8_t Address) USB_Endpoint_SelectedEndpoint = Address; Endpoint_FIFOPair_t* EndpointFIFOPair = &USB_Endpoint_FIFOs[EndpointNumber]; - USB_EndpointTable_t* EndpointTable = (USB_EndpointTable_t*)USB.EPPTR; + USB_EndpointTable_t* EndpointTable = (USB_EndpointTable_t*)USB0.EPPTR; if (Address & ENDPOINT_DIR_IN) { @@ -172,7 +172,9 @@ bool Endpoint_ConfigureEndpoint_PRV(const uint8_t Address, Endpoint_SelectEndpoint(Address); USB_Endpoint_SelectedHandle->CTRL = 0; - USB_Endpoint_SelectedHandle->STATUS = (Address & ENDPOINT_DIR_IN) ? USB_EP_BUSNACK0_bm : 0; + USB_Endpoint_ClearStatus(0xff); + if(Address & ENDPOINT_DIR_IN) + USB_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; @@ -187,8 +189,8 @@ void Endpoint_ClearEndpoints(void) { for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++) { - ((USB_EndpointTable_t*)USB.EPPTR)->Endpoints[EPNum].IN.CTRL = 0; - ((USB_EndpointTable_t*)USB.EPPTR)->Endpoints[EPNum].OUT.CTRL = 0; + ((USB_EndpointTable_t*)USB0.EPPTR)->Endpoints[EPNum].IN.CTRL = 0; + ((USB_EndpointTable_t*)USB0.EPPTR)->Endpoints[EPNum].OUT.CTRL = 0; } } diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h index 83f66455b..f8bd92bd7 100644 --- a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h +++ b/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h @@ -106,6 +106,9 @@ /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) + /* Macros: */ + #define Endpoint_waitForRMW() while(USB0.INTFLAGSB & USB_RMWBUSY_bm) + /* Type Defines: */ typedef struct { @@ -135,13 +138,46 @@ 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_EP_BUFSIZE_gp); + 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) + { + Endpoint_waitForRMW(); + + 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) + { + Endpoint_waitForRMW(); + + 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: */ @@ -226,26 +262,25 @@ const uint16_t Size, const uint8_t Banks) { - uint8_t EPConfigMask = (USB_EP_INTDSBL_bm | ((Banks > 1) ? USB_EP_PINGPONG_bm : 0) | Endpoint_BytesToEPSizeMask(Size)); + uint8_t EPConfigMask = (USB_TCDSBL_bm | Endpoint_BytesToEPSizeMask(Size)); if ((Address & ENDPOINT_EPNUM_MASK) >= ENDPOINT_TOTAL_ENDPOINTS) return false; - // TODO - Fix once limitations are lifted - EPConfigMask &= ~USB_EP_PINGPONG_bm; + // TODO - What about ISO1023? if (Size > 64) return false; switch (Type) { case EP_TYPE_CONTROL: - EPConfigMask |= USB_EP_TYPE_CONTROL_gc; + EPConfigMask |= USB_TYPE_CONTROL_gc; break; case EP_TYPE_ISOCHRONOUS: - EPConfigMask |= USB_EP_TYPE_ISOCHRONOUS_gc; + EPConfigMask |= USB_TYPE_ISO_gc; break; default: - EPConfigMask |= USB_EP_TYPE_BULK_gc; + EPConfigMask |= USB_TYPE_BULKINT_gc; break; } @@ -315,7 +350,7 @@ */ static inline void Endpoint_AbortPendingIN(void) { - USB_Endpoint_SelectedHandle->STATUS |= USB_EP_BUSNACK0_bm; + USB_Endpoint_SelectedHandle->STATUS |= USB_BUSNAK_bm; } /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint @@ -342,7 +377,7 @@ ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE static inline bool Endpoint_IsConfigured(void) { - return ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_TYPE_gm) ? true : false); + 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. @@ -412,7 +447,7 @@ ATTR_ALWAYS_INLINE static inline void Endpoint_ClearStall(void) { - USB_Endpoint_SelectedHandle->CTRL &= ~USB_EP_STALL_bm; + USB_Endpoint_SelectedHandle->CTRL &= ~USB_DOSTALL_bm; } /** Determines if the currently selected endpoint is stalled, \c false otherwise. @@ -424,14 +459,14 @@ ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE static inline bool Endpoint_IsStalled(void) { - return ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_STALL_bm) ? true : false); + 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) { - USB_Endpoint_SelectedHandle->STATUS &= ~USB_EP_TOGGLE_bm; + USB_Endpoint_ClearStatus(USB_TOGGLE_bm); } /** Determines the currently selected endpoint's direction. From c56092885e6dd407346ac48192c142ebdceb15aa Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 1 Mar 2024 16:45:50 +0100 Subject: [PATCH 10/30] Serial updated for Dx --- .../Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h | 12 +++------ .../Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h | 27 +++++-------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h index cd04ed351..a94352e72 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h +++ b/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h @@ -91,7 +91,7 @@ /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) - #define SERIAL_SPI_UBBRVAL(Baud) ((Baud < (F_CPU / 2)) ? ((F_CPU / (2 * Baud)) - 1) : 0) + #define SERIAL_SPI_BAUD(Baud) ((Baud < (F_CPU / 2)) ? ((F_CPU / (2 * Baud)) - 1) : 0) #endif /* Public Interface - May be used in end-application: */ @@ -135,11 +135,7 @@ const uint8_t SPIOptions, const uint32_t BaudRate) { - uint16_t BaudValue = SERIAL_SPI_UBBRVAL(BaudRate); - - USART->BAUDCTRLB = (BaudValue >> 8); - USART->BAUDCTRLA = (BaudValue & 0xFF); - + USART->BAUD = SERIAL_SPI_BAUD(BaudRate); USART->CTRLC = (USART_CMODE_MSPI_gc | SPIOptions); USART->CTRLB = (USART_RXEN_bm | USART_TXEN_bm); } @@ -168,10 +164,10 @@ static inline uint8_t SerialSPI_TransferByte(USART_t* const USART, const uint8_t DataByte) { - USART->DATA = DataByte; + USART->TXDATAL = DataByte; while (!(USART->STATUS & USART_TXCIF_bm)); USART->STATUS = USART_TXCIF_bm; - return USART->DATA; + return USART->RXDATAL; } /** Sends a byte through the USART SPI interface, blocking until the transfer is complete. The response diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h index 5fdfa52fb..6a24f44de 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h +++ b/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h @@ -97,23 +97,14 @@ /* Public Interface - May be used in end-application: */ /* Macros: */ - /** Macro for calculating the baud value from a given baud rate when the \c U2X (double speed) bit is - * not set. + /** Macro for calculating the baud value from a given baud rate. * * \param[in] Baud Target serial UART baud rate. * - * \return Closest UBRR register value for the given UART frequency. + * \return Closest register value for the given UART frequency. */ - #define SERIAL_UBBRVAL(Baud) ((((F_CPU / 16) + (Baud / 2)) / (Baud)) - 1) + #define SERIAL_BAUD(Baud) ((F_CPU * 64) / (16 * Baud)) - /** Macro for calculating the baud value from a given baud rate when the \c U2X (double speed) bit is - * set. - * - * \param[in] Baud Target serial UART baud rate. - * - * \return Closest UBRR register value for the given UART frequency. - */ - #define SERIAL_2X_UBBRVAL(Baud) ((((F_CPU / 8) + (Baud / 2)) / (Baud)) - 1) /* Function Prototypes: */ /** Transmits a given string located in program space (FLASH) through the USART. @@ -186,13 +177,9 @@ const uint32_t BaudRate, const bool DoubleSpeed) { - uint16_t BaudValue = (DoubleSpeed ? SERIAL_2X_UBBRVAL(BaudRate) : SERIAL_UBBRVAL(BaudRate)); - - USART->BAUDCTRLB = (BaudValue >> 8); - USART->BAUDCTRLA = (BaudValue & 0xFF); - + 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_CLK2X_bm : 0)); + USART->CTRLB = (USART_RXEN_bm | USART_TXEN_bm); } /** Turns off the USART driver, disabling and returning used hardware to their default configuration. @@ -259,7 +246,7 @@ const char DataByte) { while (!(Serial_IsSendReady(USART))); - USART->DATA = DataByte; + USART->TXDATAL = DataByte; } /** Receives the next byte from the USART. @@ -275,7 +262,7 @@ return -1; USART->STATUS = USART_RXCIF_bm; - return USART->DATA; + return USART->RXDATAL; } /* Disable C linkage for C++ Compilers: */ From ce491907d23abda690991ed3daaa73ab437549e1 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Mon, 4 Mar 2024 09:23:50 +0100 Subject: [PATCH 11/30] SPI Updated for Dx --- LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h index ddd8d6ce0..617a88931 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h +++ b/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h @@ -104,19 +104,19 @@ #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 | (1 << SPI_PRESCALER_gp)) + #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 (1 << SPI_PRESCALER_gp) + #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 | (2 << SPI_PRESCALER_gp)) + #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 (2 << SPI_PRESCALER_gp) + #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 (3 << SPI_PRESCALER_gp) + #define SPI_SPEED_FCPU_DIV_128 SPI_PRESC_DIV128_gc /**@}*/ /** \name SPI SCK Polarity Configuration Masks */ @@ -125,7 +125,7 @@ #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_MODE1_bm + #define SPI_SCK_LEAD_FALLING SPI_MODE_1_bm /**@}*/ /** \name SPI Sample Edge Configuration Masks */ @@ -134,7 +134,7 @@ #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_MODE0_bm + #define SPI_SAMPLE_TRAILING SPI_MODE_0_bm /**@}*/ /** \name SPI Data Ordering Configuration Masks */ @@ -168,7 +168,7 @@ static inline void SPI_Init(SPI_t* const SPI, const uint8_t SPIOptions) { - SPI->CTRL = (SPIOptions | SPI_ENABLE_bm); + SPI->CTRLA = (SPIOptions | SPI_ENABLE_bm); } /** Turns off the SPI driver, disabling and returning used hardware to their default configuration. @@ -178,7 +178,7 @@ ATTR_NON_NULL_PTR_ARG(1) static inline void SPI_Disable(SPI_t* const SPI) { - SPI->CTRL &= ~SPI_ENABLE_bm; + SPI->CTRLA &= ~SPI_ENABLE_bm; } /** Retrieves the currently selected SPI mode, once the SPI interface has been configured. @@ -190,7 +190,7 @@ ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) static inline uint8_t SPI_GetCurrentMode(SPI_t* const SPI) { - return (SPI->CTRL & SPI_MASTER_bm); + return (SPI->CTRLA & SPI_MASTER_bm); } /** Sends and receives a byte through the SPI interface, blocking until the transfer is complete. @@ -206,7 +206,7 @@ const uint8_t Byte) { SPI->DATA = Byte; - while (!(SPI->STATUS & SPI_IF_bm)); + while (!(SPI->INTFLAGS & SPI_IF_bm)); return SPI->DATA; } @@ -222,7 +222,7 @@ const uint8_t Byte) { SPI->DATA = Byte; - while (!(SPI->STATUS & SPI_IF_bm)); + while (!(SPI->INTFLAGS & SPI_IF_bm)); } /** Sends a dummy byte through the SPI interface, blocking until the transfer is complete. The response @@ -236,7 +236,7 @@ static inline uint8_t SPI_ReceiveByte(SPI_t* const SPI) { SPI->DATA = 0; - while (!(SPI->STATUS & SPI_IF_bm)); + while (!(SPI->INTFLAGS & SPI_IF_bm)); return SPI->DATA; } From 3deb24b0775cf1954719c3b2efc4130a315c89d6 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Mon, 4 Mar 2024 09:24:01 +0100 Subject: [PATCH 12/30] TWI updated for Dx --- LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c | 30 ++++++++++----------- LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h | 13 +++++---- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c index 1e44d1127..4618213dc 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c +++ b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c @@ -40,23 +40,23 @@ uint8_t TWI_StartTransmission(TWI_t* const TWI, { uint16_t TimeoutRemaining; - TWI->MASTER.ADDR = SlaveAddress; + TWI->MADDR = SlaveAddress; TimeoutRemaining = (TimeoutMS * 100); while (TimeoutRemaining) { - uint8_t status = TWI->MASTER.STATUS; + uint8_t status = TWI->MSTATUS; - if ((status & (TWI_MASTER_WIF_bm | TWI_MASTER_ARBLOST_bm)) == (TWI_MASTER_WIF_bm | TWI_MASTER_ARBLOST_bm)) + if ((status & (TWI_WIF_bm | TWI_ARBLOST_bm)) == (TWI_WIF_bm | TWI_ARBLOST_bm)) { - TWI->MASTER.ADDR = SlaveAddress; + TWI->MADDR = SlaveAddress; } - else if ((status & (TWI_MASTER_WIF_bm | TWI_MASTER_RXACK_bm)) == (TWI_MASTER_WIF_bm | TWI_MASTER_RXACK_bm)) + 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_MASTER_WIF_bm | TWI_MASTER_RIF_bm)) + else if (status & (TWI_WIF_bm | TWI_RIF_bm)) { return TWI_ERROR_NoError; } @@ -66,7 +66,7 @@ uint8_t TWI_StartTransmission(TWI_t* const TWI, } if (!(TimeoutRemaining)) { - if (TWI->MASTER.STATUS & TWI_MASTER_CLKHOLD_bm) { + if (TWI->MSTATUS & TWI_CLKHOLD_bm) { TWI_StopTransmission(TWI); } } @@ -77,29 +77,29 @@ uint8_t TWI_StartTransmission(TWI_t* const TWI, bool TWI_SendByte(TWI_t* const TWI, const uint8_t Byte) { - TWI->MASTER.DATA = Byte; + TWI->MDATA = Byte; - while (!(TWI->MASTER.STATUS & TWI_MASTER_WIF_bm)); + while (!(TWI->MSTATUS & TWI_WIF_bm)); - return (TWI->MASTER.STATUS & TWI_MASTER_WIF_bm) && !(TWI->MASTER.STATUS & TWI_MASTER_RXACK_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->MASTER.STATUS & (TWI_MASTER_BUSERR_bm | TWI_MASTER_ARBLOST_bm)) == (TWI_MASTER_BUSERR_bm | TWI_MASTER_ARBLOST_bm)) { + if ((TWI->MSTATUS & (TWI_BUSERR_bm | TWI_ARBLOST_bm)) == (TWI_BUSERR_bm | TWI_ARBLOST_bm)) { return false; } - while (!(TWI->MASTER.STATUS & TWI_MASTER_RIF_bm)); + while (!(TWI->MSTATUS & TWI_RIF_bm)); - *Byte = TWI->MASTER.DATA; + *Byte = TWI->MDATA; if (LastByte) - TWI->MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc; + TWI->MCTRLB = TWI_ACKACT_bm | TWI_MCMD_STOP_gc; else - TWI->MASTER.CTRLC = TWI_MASTER_CMD_RECVTRANS_gc; + TWI->MCTRLB = TWI_MCMD_RECVTRANS_gc; return true; } diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h index 01432ea8c..d2c60e529 100644 --- a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h +++ b/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h @@ -186,11 +186,10 @@ static inline void TWI_Init(TWI_t* const TWI, const uint8_t Baud) { - TWI->CTRL = 0x00; - TWI->MASTER.BAUD = Baud; - TWI->MASTER.CTRLA = TWI_MASTER_ENABLE_bm; - TWI->MASTER.CTRLB = 0; - TWI->MASTER.STATUS = TWI_MASTER_BUSSTATE_IDLE_gc; + 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 @@ -201,7 +200,7 @@ ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) static inline void TWI_Disable(TWI_t* const TWI) { - TWI->MASTER.CTRLA &= ~TWI_MASTER_ENABLE_bm; + TWI->MCTRLA &= ~TWI_ENABLE_bm; } /** Sends a TWI STOP onto the TWI bus, terminating communication with the currently addressed device. @@ -211,7 +210,7 @@ ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1) static inline void TWI_StopTransmission(TWI_t* const TWI) { - TWI->MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc; + TWI->MCTRLB = TWI_ACKACT_bm | TWI_MCMD_STOP_gc; } /* Function Prototypes: */ From 698f0d0c64c678f5d8a85cf0dec7cde5d8e54895 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Mon, 4 Mar 2024 09:41:24 +0100 Subject: [PATCH 13/30] Updated board files for AVR DU CNANO --- .../Board/AVR_Dx/AVR64DU32_CNANO/Board.h | 18 ++-- .../Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h | 44 ++++------ .../Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h | 82 ++++++------------- LUFA/Drivers/Board/Board.h | 2 + LUFA/Drivers/Board/Buttons.h | 2 + LUFA/Drivers/Board/LEDs.h | 2 + 6 files changed, 52 insertions(+), 98 deletions(-) diff --git a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h index 62456c43f..dd0711229 100644 --- a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h +++ b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h @@ -29,29 +29,28 @@ */ /** \file - * \brief Board specific information header for the Atmel XMEGA A3BU Xplained. - * \copydetails Group_BoardInfo_A3BU_XPLAINED + * \brief Board specific information header for the x. + * \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_A3BU_XPLAINED A3BU_XPLAINED - * \brief Board specific information header for the Atmel XMEGA A3BU Xplained. + * \defgroup Group_BoardInfo_AVR64DU32_CNANO AVR64DU32_CNANO + * \brief Board specific information header for the Microchip AVR64DU32 Curiosity Nano. * - * Board specific information header for the Atmel XMEGA A3BU Xplained. + * Board specific information header for the Microchip AVR64DU32 Curiosity Nano. * * @{ */ -#ifndef __BOARD_A3BU_XPLAINED_H__ -#define __BOARD_A3BU_XPLAINED_H__ +#ifndef __BOARD_AVR64DU32_CNANO_H__ +#define __BOARD_AVR64DU32_CNANO_H__ /* Includes: */ #include "../../../../Common/Common.h" #include "../../Buttons.h" - #include "../../Dataflash.h" #include "../../LEDs.h" /* Enable C linkage for C++ Compilers: */ @@ -69,9 +68,6 @@ /** Indicates the board has hardware Buttons mounted. */ #define BOARD_HAS_BUTTONS - /** Indicates the board has a hardware Dataflash mounted. */ - #define BOARD_HAS_DATAFLASH - /** Indicates the board has hardware LEDs mounted. */ #define BOARD_HAS_LEDS diff --git a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h index 6b1ada001..98dd4ccb2 100644 --- a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h +++ b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h @@ -29,31 +29,29 @@ */ /** \file - * \brief Board specific Buttons driver header for the Atmel XMEGA A3BU Xplained. - * \copydetails Group_Buttons_A3BU_XPLAINED + * \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_A3BU_XPLAINED A3BU_XPLAINED - * \brief Board specific Buttons driver header for the Atmel XMEGA A3BU Xplained. + * \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 Atmel XMEGA A3BU Xplained. + * Board specific Buttons driver header for the Microchip AVR64DU32 Curiosity Nano. * * * - * - * - * + * *
NameInfoActive LevelPort Pin
BUTTONS_BUTTON1SW0 ButtonLowPORTE.5
BUTTONS_BUTTON2SW1 ButtonLowPORTF.1
BUTTONS_BUTTON3SW2 ButtonLowPORTF.2
BUTTONS_BUTTON1SW0 ButtonLowPORTF.6
* * @{ */ -#ifndef __BUTTONS_A3BU_XPLAINED_H__ -#define __BUTTONS_A3BU_XPLAINED_H__ +#ifndef __BUTTONS_AVR64DU32_CNANO_H__ +#define __BUTTONS_AVR64DU32_CNANO_H__ /* Includes: */ #include @@ -71,40 +69,26 @@ /* Public Interface - May be used in end-application: */ /* Macros: */ /** Button mask for the first button on the board. */ - #define BUTTONS_BUTTON1 (1 << 5) - - /** Button mask for the second button on the board. */ - #define BUTTONS_BUTTON2 (1 << 1) - - /** Button mask for the third button on the board. */ - #define BUTTONS_BUTTON3 (1 << 2) + #define BUTTONS_BUTTON1 PIN6_bm /* Inline Functions: */ #if !defined(__DOXYGEN__) static inline void Buttons_Init(void) { - PORTE.OUTCLR = BUTTONS_BUTTON1; - PORTE.PIN5CTRL = (PORT_OPC_PULLUP_gc | PORT_INVEN_bm); - - PORTF.OUTCLR = (BUTTONS_BUTTON2 | BUTTONS_BUTTON3); - PORTF.PIN1CTRL = (PORT_OPC_PULLUP_gc | PORT_INVEN_bm); - PORTF.PIN2CTRL = (PORT_OPC_PULLUP_gc | PORT_INVEN_bm); + PORTF.OUTCLR = BUTTONS_BUTTON1; + PORTF.PIN6CTRL = (PORT_PULLUPEN_bm | PORT_INVEN_bm); } static inline void Buttons_Disable(void) { - PORTE.OUTCLR = BUTTONS_BUTTON1; - PORTE.PIN5CTRL = 0; - - PORTF.OUTCLR = (BUTTONS_BUTTON2 | BUTTONS_BUTTON3); - PORTF.PIN1CTRL = 0; - PORTF.PIN2CTRL = 0; + PORTF.OUTCLR = BUTTONS_BUTTON1; + PORTF.PIN6CTRL = 0; } ATTR_WARN_UNUSED_RESULT static inline uint8_t Buttons_GetStatus(void) { - return ((PORTE_IN & BUTTONS_BUTTON1) | (PORTF_IN & (BUTTONS_BUTTON2 | BUTTONS_BUTTON3))); + return (VPORTF.IN & BUTTONS_BUTTON1); } #endif diff --git a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h index 62b231477..40c34a8c9 100644 --- a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h +++ b/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h @@ -29,32 +29,29 @@ */ /** \file - * \brief Board specific LED driver header for the Atmel XMEGA A3BU Xplained. - * \copydetails Group_LEDs_A3BU_XPLAINED + * \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_A3BU_XPLAINED A3BU_XPLAINED - * \brief Board specific LED driver header for the Atmel XMEGA A3BU Xplained. + * \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 Atmel XMEGA A3BU Xplained. + * Board specific LED driver header for the Microchip AVR64DU32 Curiosity Nano. * * * - * - * - * - * + * *
NameColorInfoActive LevelPort Pin
LEDS_LED1YellowLED0 LEDLowPORTR.0
LEDS_LED2YellowLED1 LEDLowPORTR.1
LEDS_LED3RedStatus Bicolour Red LEDLowPORTD.4
LEDS_LED4GreenStatus Bicolour Green LEDHighPORTD.5
LEDS_LED1YellowLED0 LEDLowPORTF.2
* * @{ */ -#ifndef __LEDS_A3BU_XPLAINED_H__ -#define __LEDS_A3BU_XPLAINED_H__ +#ifndef __LEDS_AVR64DU32_CNANO_H__ +#define __LEDS_AVR64DU32_CNANO_H__ /* Includes: */ #include @@ -72,26 +69,16 @@ /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ - #define LEDS_PORTR_LEDS (LEDS_LED1 | LEDS_LED2) - #define LEDS_PORTD_LEDS (LEDS_LED3 | LEDS_LED4) + #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 (1 << 0) - - /** LED mask for the second LED on the board. */ - #define LEDS_LED2 (1 << 1) - - /** LED mask for the third LED on the board. */ - #define LEDS_LED3 (1 << 4) - - /** LED mask for the fourth LED on the board. */ - #define LEDS_LED4 (1 << 5) + #define LEDS_LED1 PIN2_bm /** LED mask for all the LEDs on the board. */ - #define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4) + #define LEDS_ALL_LEDS (LEDS_LED1) /** LED mask for none of the board LEDs. */ #define LEDS_NO_LEDS 0 @@ -100,73 +87,54 @@ #if !defined(__DOXYGEN__) static inline void LEDs_Init(void) { - PORTR.DIRSET = LEDS_PORTR_LEDS; - PORTR.OUTCLR = LEDS_PORTR_LEDS; - - PORTCFG.MPCMASK = LEDS_PORTR_LEDS; - PORTR.PIN0CTRL = PORT_INVEN_bm; + PORTF.DIRSET = LEDS_PORTF_LEDS; + PORTF.OUTCLR = LEDS_PORTF_LEDS; - PORTD.DIRSET = LEDS_PORTD_LEDS; - PORTD.OUTCLR = LEDS_PORTD_LEDS; - - PORTD.PIN4CTRL = PORT_INVEN_bm; + PORTF.PIN2CTRL = PORT_INVEN_bm; } static inline void LEDs_Disable(void) { - PORTR.DIRCLR = LEDS_PORTR_LEDS; - PORTR.OUTCLR = LEDS_PORTR_LEDS; - - PORTCFG.MPCMASK = 0; - PORTR.PIN0CTRL = LEDS_PORTR_LEDS; - - PORTD.DIRCLR = LEDS_PORTD_LEDS; - PORTD.OUTCLR = LEDS_PORTD_LEDS; + PORTF.DIRCLR = LEDS_PORTF_LEDS; + PORTF.OUTCLR = LEDS_PORTF_LEDS; - PORTD.PIN4CTRL = 0; + PORTF.PIN2CTRL = 0; } static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) { - PORTR_OUTSET = LEDMask & LEDS_PORTR_LEDS; - PORTD_OUTSET = LEDMask & LEDS_PORTD_LEDS; + PORTF.OUTSET = LEDMask & LEDS_PORTF_LEDS; } static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) { - PORTR_OUTCLR = LEDMask & LEDS_PORTR_LEDS; - PORTD_OUTCLR = LEDMask & LEDS_PORTD_LEDS; + PORTF.OUTCLR = LEDMask & LEDS_PORTF_LEDS; } static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) { - PORTR_OUTCLR = LEDS_PORTR_LEDS; - PORTD_OUTCLR = LEDS_PORTD_LEDS; + PORTF.OUTCLR = LEDS_PORTF_LEDS; - PORTR_OUTSET = (LEDMask & LEDS_PORTR_LEDS); - PORTD_OUTSET = (LEDMask & LEDS_PORTD_LEDS); + PORTF.OUTSET = (LEDMask & LEDS_PORTF_LEDS); } static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask) { - PORTR_OUTCLR = (LEDMask & LEDS_PORTR_LEDS); - PORTD_OUTCLR = (LEDMask & LEDS_PORTD_LEDS); + PORTF.OUTCLR = (LEDMask & LEDS_PORTF_LEDS); - PORTR_OUTSET = (ActiveMask & LEDS_PORTR_LEDS); - PORTD_OUTSET = (ActiveMask & LEDS_PORTD_LEDS); + PORTF.OUTSET = (ActiveMask & LEDS_PORTF_LEDS); } static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) { - PORTR_OUTTGL = (LEDMask & LEDS_PORTR_LEDS); - PORTD_OUTTGL = (LEDMask & LEDS_PORTD_LEDS); + PORTF.OUTTGL = (LEDMask & LEDS_PORTF_LEDS); } ATTR_WARN_UNUSED_RESULT static inline uint8_t LEDs_GetLEDs(void) { - return ((PORTR_OUT & LEDS_PORTR_LEDS) | (PORTD_OUT & LEDS_PORTD_LEDS)); + return (PORTF_OUT & LEDS_PORTF_LEDS); } #endif diff --git a/LUFA/Drivers/Board/Board.h b/LUFA/Drivers/Board/Board.h index fc6c3f2d3..4df199b05 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 "AVR_Dx/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..b481d4da2 100644 --- a/LUFA/Drivers/Board/Buttons.h +++ b/LUFA/Drivers/Board/Buttons.h @@ -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 "AVR_Dx/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..60639ffd4 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 "AVR_Dx/AVR64DU32_CNANO/LEDs.h" #else #include "Board/LEDs.h" #endif From 4369ee756e2d4c23eba6b1435bb8fe29128bccdd Mon Sep 17 00:00:00 2001 From: echoromeo Date: Wed, 6 Mar 2024 16:03:28 +0100 Subject: [PATCH 14/30] Renaming files and folders according to ARCH --- LUFA/Drivers/Board/Board.h | 2 +- LUFA/Drivers/Board/Buttons.h | 2 +- LUFA/Drivers/Board/LEDs.h | 2 +- .../Peripheral/{AVR_Dx/SPI_AVR_Dx.h => AVRDX/SPI_AVRDX.h} | 0 .../SerialSPI_AVR_Dx.h => AVRDX/SerialSPI_AVRDX.h} | 0 .../{AVR_Dx/Serial_AVR_Dx.c => AVRDX/Serial_AVRDX.c} | 0 .../{AVR_Dx/Serial_AVR_Dx.h => AVRDX/Serial_AVRDX.h} | 0 .../Peripheral/{AVR_Dx/TWI_AVR_Dx.c => AVRDX/TWI_AVRDX.c} | 0 .../Peripheral/{AVR_Dx/TWI_AVR_Dx.h => AVRDX/TWI_AVRDX.h} | 0 LUFA/Drivers/Peripheral/SPI.h | 2 +- LUFA/Drivers/Peripheral/Serial.h | 2 +- LUFA/Drivers/Peripheral/SerialSPI.h | 2 +- LUFA/Drivers/Peripheral/TWI.h | 2 +- .../Core/{AVR_Dx/Device_AVR_Dx.c => AVRDX/Device_AVRDX.c} | 0 .../Core/{AVR_Dx/Device_AVR_Dx.h => AVRDX/Device_AVRDX.h} | 0 .../EndpointStream_AVRDX.c} | 0 .../EndpointStream_AVRDX.h} | 0 .../{AVR_Dx/Endpoint_AVR_Dx.c => AVRDX/Endpoint_AVRDX.c} | 0 .../{AVR_Dx/Endpoint_AVR_Dx.h => AVRDX/Endpoint_AVRDX.h} | 0 .../USB/Core/{AVR_Dx/Host_AVR_Dx.c => AVRDX/Host_AVRDX.c} | 0 .../PipeStream_AVR_Dx.c => AVRDX/PipeStream_AVRDX.c} | 0 .../USB/Core/{AVR_Dx/Pipe_AVR_Dx.c => AVRDX/Pipe_AVRDX.c} | 0 .../Template/Template_Endpoint_Control_R.c | 0 .../Template/Template_Endpoint_Control_W.c | 0 .../{AVR_Dx => AVRDX}/Template/Template_Endpoint_RW.c | 0 .../USBController_AVRDX.c} | 0 .../USBController_AVRDX.h} | 0 .../USBInterrupt_AVR_Dx.c => AVRDX/USBInterrupt_AVRDX.c} | 0 .../USBInterrupt_AVR_Dx.h => AVRDX/USBInterrupt_AVRDX.h} | 0 LUFA/Drivers/USB/Core/Device.h | 2 +- LUFA/Drivers/USB/Core/Endpoint.h | 2 +- LUFA/Drivers/USB/Core/EndpointStream.h | 2 +- LUFA/Drivers/USB/Core/USBController.h | 2 +- LUFA/Drivers/USB/Core/USBInterrupt.h | 2 +- LUFA/Drivers/USB/Core/USBMode.h | 8 ++++++++ .../AVRDXExperimentalInfo.txt} | 0 LUFA/Platform/{AVR_Dx => AVRDX}/ClockManagement.h | 4 ++-- LUFA/Platform/Platform.h | 2 +- 38 files changed, 23 insertions(+), 15 deletions(-) rename LUFA/Drivers/Peripheral/{AVR_Dx/SPI_AVR_Dx.h => AVRDX/SPI_AVRDX.h} (100%) rename LUFA/Drivers/Peripheral/{AVR_Dx/SerialSPI_AVR_Dx.h => AVRDX/SerialSPI_AVRDX.h} (100%) rename LUFA/Drivers/Peripheral/{AVR_Dx/Serial_AVR_Dx.c => AVRDX/Serial_AVRDX.c} (100%) rename LUFA/Drivers/Peripheral/{AVR_Dx/Serial_AVR_Dx.h => AVRDX/Serial_AVRDX.h} (100%) rename LUFA/Drivers/Peripheral/{AVR_Dx/TWI_AVR_Dx.c => AVRDX/TWI_AVRDX.c} (100%) rename LUFA/Drivers/Peripheral/{AVR_Dx/TWI_AVR_Dx.h => AVRDX/TWI_AVRDX.h} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/Device_AVR_Dx.c => AVRDX/Device_AVRDX.c} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/Device_AVR_Dx.h => AVRDX/Device_AVRDX.h} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/EndpointStream_AVR_Dx.c => AVRDX/EndpointStream_AVRDX.c} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/EndpointStream_AVR_Dx.h => AVRDX/EndpointStream_AVRDX.h} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/Endpoint_AVR_Dx.c => AVRDX/Endpoint_AVRDX.c} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/Endpoint_AVR_Dx.h => AVRDX/Endpoint_AVRDX.h} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/Host_AVR_Dx.c => AVRDX/Host_AVRDX.c} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/PipeStream_AVR_Dx.c => AVRDX/PipeStream_AVRDX.c} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/Pipe_AVR_Dx.c => AVRDX/Pipe_AVRDX.c} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx => AVRDX}/Template/Template_Endpoint_Control_R.c (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx => AVRDX}/Template/Template_Endpoint_Control_W.c (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx => AVRDX}/Template/Template_Endpoint_RW.c (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/USBController_AVR_Dx.c => AVRDX/USBController_AVRDX.c} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/USBController_AVR_Dx.h => AVRDX/USBController_AVRDX.h} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/USBInterrupt_AVR_Dx.c => AVRDX/USBInterrupt_AVRDX.c} (100%) rename LUFA/Drivers/USB/Core/{AVR_Dx/USBInterrupt_AVR_Dx.h => AVRDX/USBInterrupt_AVRDX.h} (100%) rename LUFA/Platform/{AVR_Dx/AVR_DxExperimentalInfo.txt => AVRDX/AVRDXExperimentalInfo.txt} (100%) rename LUFA/Platform/{AVR_Dx => AVRDX}/ClockManagement.h (99%) diff --git a/LUFA/Drivers/Board/Board.h b/LUFA/Drivers/Board/Board.h index 4df199b05..af28f7334 100644 --- a/LUFA/Drivers/Board/Board.h +++ b/LUFA/Drivers/Board/Board.h @@ -163,7 +163,7 @@ #elif (BOARD == BOARD_XPLAINED_MINI) #include "AVR8/XPLAINED_MINI/Board.h" #elif (BOARD == BOARD_AVR64DU32_CNANO) - #include "AVR_Dx/AVR64DU32_CNANO/Board.h" + #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 b481d4da2..0b5070ca2 100644 --- a/LUFA/Drivers/Board/Buttons.h +++ b/LUFA/Drivers/Board/Buttons.h @@ -161,7 +161,7 @@ #elif (BOARD == BOARD_U2S) #include "AVR8/U2S/Buttons.h" #elif (BOARD == BOARD_AVR64DU32_CNANO) - #include "AVR_Dx/AVR64DU32_CNANO/Buttons.h" + #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 60639ffd4..c7a8f55cb 100644 --- a/LUFA/Drivers/Board/LEDs.h +++ b/LUFA/Drivers/Board/LEDs.h @@ -213,7 +213,7 @@ #elif (BOARD == BOARD_XPLAINED_MINI) #include "AVR8/XPLAINED_MINI/LEDs.h" #elif (BOARD == BOARD_AVR64DU32_CNANO) - #include "AVR_Dx/AVR64DU32_CNANO/LEDs.h" + #include "AVRDX/AVR64DU32_CNANO/LEDs.h" #else #include "Board/LEDs.h" #endif diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVRDX/SPI_AVRDX.h similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/SPI_AVR_Dx.h rename to LUFA/Drivers/Peripheral/AVRDX/SPI_AVRDX.h diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVRDX/SerialSPI_AVRDX.h similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/SerialSPI_AVR_Dx.h rename to LUFA/Drivers/Peripheral/AVRDX/SerialSPI_AVRDX.h diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c b/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.c similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.c rename to LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.c diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/Serial_AVR_Dx.h rename to LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c b/LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.c similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.c rename to LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.c diff --git a/LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h b/LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.h similarity index 100% rename from LUFA/Drivers/Peripheral/AVR_Dx/TWI_AVR_Dx.h rename to LUFA/Drivers/Peripheral/AVRDX/TWI_AVRDX.h diff --git a/LUFA/Drivers/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h index 6a5126186..f0c560065 100644 --- a/LUFA/Drivers/Peripheral/SPI.h +++ b/LUFA/Drivers/Peripheral/SPI.h @@ -69,7 +69,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/SPI_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/SPI_AVR_Dx.h" + #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 6a3d3fb30..27c01cedc 100644 --- a/LUFA/Drivers/Peripheral/Serial.h +++ b/LUFA/Drivers/Peripheral/Serial.h @@ -69,7 +69,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/Serial_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/Serial_AVR_Dx.h" + #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 9c05f6d66..aa9b1bf5f 100644 --- a/LUFA/Drivers/Peripheral/SerialSPI.h +++ b/LUFA/Drivers/Peripheral/SerialSPI.h @@ -69,7 +69,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/SerialSPI_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/SerialSPI_AVR_Dx.h" + #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 e917c3e14..72f53b90e 100644 --- a/LUFA/Drivers/Peripheral/TWI.h +++ b/LUFA/Drivers/Peripheral/TWI.h @@ -69,7 +69,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/TWI_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/TWI_AVR_Dx.h" + #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/AVR_Dx/Device_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.c rename to LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Device_AVR_Dx.h rename to LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.c rename to LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/EndpointStream_AVR_Dx.h rename to LUFA/Drivers/USB/Core/AVRDX/EndpointStream_AVRDX.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.c rename to LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Endpoint_AVR_Dx.h rename to LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVRDX/Host_AVRDX.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Host_AVR_Dx.c rename to LUFA/Drivers/USB/Core/AVRDX/Host_AVRDX.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVRDX/PipeStream_AVRDX.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/PipeStream_AVR_Dx.c rename to LUFA/Drivers/USB/Core/AVRDX/PipeStream_AVRDX.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Pipe_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVRDX/Pipe_AVRDX.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Pipe_AVR_Dx.c rename to LUFA/Drivers/USB/Core/AVRDX/Pipe_AVRDX.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_Control_R.c b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_R.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_Control_R.c rename to LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_R.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_Control_W.c b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_W.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_Control_W.c rename to LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_Control_W.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_RW.c b/LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_RW.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/Template/Template_Endpoint_RW.c rename to LUFA/Drivers/USB/Core/AVRDX/Template/Template_Endpoint_RW.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.c rename to LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/USBController_AVR_Dx.h rename to LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.c rename to LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c diff --git a/LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h similarity index 100% rename from LUFA/Drivers/USB/Core/AVR_Dx/USBInterrupt_AVR_Dx.h rename to LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h diff --git a/LUFA/Drivers/USB/Core/Device.h b/LUFA/Drivers/USB/Core/Device.h index 09d3c0733..b336763c0 100644 --- a/LUFA/Drivers/USB/Core/Device.h +++ b/LUFA/Drivers/USB/Core/Device.h @@ -147,7 +147,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/Device_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/Device_AVR_Dx.h" + #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 518d2b34a..e4c90cfc4 100644 --- a/LUFA/Drivers/USB/Core/Endpoint.h +++ b/LUFA/Drivers/USB/Core/Endpoint.h @@ -118,7 +118,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/Endpoint_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/Endpoint_AVR_Dx.h" + #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 c5c13d64f..00b974d02 100644 --- a/LUFA/Drivers/USB/Core/EndpointStream.h +++ b/LUFA/Drivers/USB/Core/EndpointStream.h @@ -112,7 +112,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/EndpointStream_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/EndpointStream_AVR_Dx.h" + #include "AVRDX/EndpointStream_AVRDX.h" #endif /* Disable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/Core/USBController.h b/LUFA/Drivers/USB/Core/USBController.h index 064a956e3..b700386d2 100644 --- a/LUFA/Drivers/USB/Core/USBController.h +++ b/LUFA/Drivers/USB/Core/USBController.h @@ -153,7 +153,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/USBController_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/USBController_AVR_Dx.h" + #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 373796449..20614fcbf 100644 --- a/LUFA/Drivers/USB/Core/USBInterrupt.h +++ b/LUFA/Drivers/USB/Core/USBInterrupt.h @@ -63,7 +63,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/USBInterrupt_XMEGA.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/USBInterrupt_AVR_Dx.h" + #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/AVR_Dx/AVR_DxExperimentalInfo.txt b/LUFA/Platform/AVRDX/AVRDXExperimentalInfo.txt similarity index 100% rename from LUFA/Platform/AVR_Dx/AVR_DxExperimentalInfo.txt rename to LUFA/Platform/AVRDX/AVRDXExperimentalInfo.txt diff --git a/LUFA/Platform/AVR_Dx/ClockManagement.h b/LUFA/Platform/AVRDX/ClockManagement.h similarity index 99% rename from LUFA/Platform/AVR_Dx/ClockManagement.h rename to LUFA/Platform/AVRDX/ClockManagement.h index 7d83cb5f4..0828c4fe6 100644 --- a/LUFA/Platform/AVR_Dx/ClockManagement.h +++ b/LUFA/Platform/AVRDX/ClockManagement.h @@ -36,7 +36,7 @@ */ /** \ingroup Group_PlatformDrivers_AVRDX - * \defgroup Group_PlatformDrivers_AVRDXClocks Clock Management Driver - LUFA/Platform/AVR_Dx/ClockManagement.h + * \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 @@ -49,7 +49,7 @@ * * Usage Example: * \code - * #include + * #include * * void main(void) * { diff --git a/LUFA/Platform/Platform.h b/LUFA/Platform/Platform.h index fcc46269e..a01180589 100644 --- a/LUFA/Platform/Platform.h +++ b/LUFA/Platform/Platform.h @@ -75,7 +75,7 @@ #elif (ARCH == ARCH_XMEGA) #include "XMEGA/ClockManagement.h" #elif (ARCH == ARCH_AVRDX) - #include "AVR_Dx/ClockManagement.h" + #include "AVRDX/ClockManagement.h" #endif #endif From 448563ab2cbfc622b8af26a8c3483ba902c12187 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Wed, 6 Mar 2024 16:07:39 +0100 Subject: [PATCH 15/30] BuildTests updated for AVR Dx --- BuildTests/BoardDriverTest/BoardDeviceMap.cfg | 3 +++ BuildTests/BoardDriverTest/makefile | 1 + BuildTests/ModuleTest/makefile | 11 +++++++++-- BuildTests/ModuleTest/makefile.test | 2 ++ BuildTests/SingleUSBModeTest/makefile | 4 ++++ BuildTests/SingleUSBModeTest/makefile.test | 2 ++ LUFA/Build/DMBS/DMBS/gcc.mk | 6 ++++-- LUFA/Build/LUFA/lufa-gcc.mk | 2 ++ LUFA/Common/BoardTypes.h | 2 ++ LUFA/makefile | 2 +- 10 files changed, 30 insertions(+), 5 deletions(-) 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/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..756b2c36e 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=avr64du32u 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=avr64du32u %: 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/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/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/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 From c5ee47f9b3f6d3efea3edae77e7eb1018591925b Mon Sep 17 00:00:00 2001 From: echoromeo Date: Wed, 6 Mar 2024 17:24:07 +0100 Subject: [PATCH 16/30] Build failures fix --- LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h | 2 +- LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c | 20 ++++++++++---------- LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h | 9 +++------ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h index 8bc22674c..a74e57d36 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h @@ -196,7 +196,7 @@ uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); GlobalInterruptDisable(); - uint8_t* SigReadAddress = INTERNAL_SERIAL_START_ADDRESS; + uint8_t* SigReadAddress = (uint8_t *) INTERNAL_SERIAL_START_ADDRESS; for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++) { diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c index e0fd6641f..a90e9487f 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c @@ -52,14 +52,14 @@ bool Endpoint_IsINReady(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); - return ((USB_Endpoint_GetStatus() & USB_BUSNAK_bm) ? true : false); + return ((Endpoint_GetStatus() & USB_BUSNAK_bm) ? true : false); } bool Endpoint_IsOUTReceived(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); - if (USB_Endpoint_GetStatus() & USB_TRNCOMPL_bm) + if (Endpoint_GetStatus() & USB_TRNCOMPL_bm) { USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; return true; @@ -72,7 +72,7 @@ bool Endpoint_IsSETUPReceived(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); - if (USB_Endpoint_GetStatus() & USB_SETUP_bm) + if (Endpoint_GetStatus() & USB_SETUP_bm) { USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; return true; @@ -84,25 +84,25 @@ bool Endpoint_IsSETUPReceived(void) void Endpoint_ClearSETUP(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); - USB_Endpoint_ClearStatus(USB_SETUP_bm | USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); - USB_Endpoint_SetStatus(USB_TOGGLE_bm); + Endpoint_ClearStatus(USB_SETUP_bm | USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); + Endpoint_SetStatus(USB_TOGGLE_bm); USB_Endpoint_SelectedFIFO->Position = 0; Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); - USB_Endpoint_SetStatus(USB_TOGGLE_bm); + Endpoint_SetStatus(USB_TOGGLE_bm); USB_Endpoint_SelectedFIFO->Position = 0; } void Endpoint_ClearIN(void) { USB_Endpoint_SelectedHandle->CNT = USB_Endpoint_SelectedFIFO->Position; - USB_Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); + Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); USB_Endpoint_SelectedFIFO->Position = 0; } void Endpoint_ClearOUT(void) { - USB_Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); + Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); USB_Endpoint_SelectedFIFO->Position = 0; } @@ -172,9 +172,9 @@ bool Endpoint_ConfigureEndpoint_PRV(const uint8_t Address, Endpoint_SelectEndpoint(Address); USB_Endpoint_SelectedHandle->CTRL = 0; - USB_Endpoint_ClearStatus(0xff); + Endpoint_ClearStatus(0xff); if(Address & ENDPOINT_DIR_IN) - USB_Endpoint_SetStatus(USB_BUSNAK_bm); + 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; diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h index f8bd92bd7..183d46d9c 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h @@ -106,9 +106,6 @@ /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) - /* Macros: */ - #define Endpoint_waitForRMW() while(USB0.INTFLAGSB & USB_RMWBUSY_bm) - /* Type Defines: */ typedef struct { @@ -159,7 +156,7 @@ static inline void Endpoint_ClearStatus(const uint8_t Config) ATTR_CONST ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearStatus(const uint8_t Config) { - Endpoint_waitForRMW(); + while(USB0.INTFLAGSB & USB_RMWBUSY_bm); if(USB_Endpoint_SelectedEndpoint & ENDPOINT_DIR_IN) { USB0.STATUS[USB_Endpoint_SelectedEndpoint & ENDPOINT_EPNUM_MASK].INCLR = Config; @@ -171,7 +168,7 @@ static inline void Endpoint_SetStatus(const uint8_t Config) ATTR_CONST ATTR_ALWAYS_INLINE; static inline void Endpoint_SetStatus(const uint8_t Config) { - Endpoint_waitForRMW(); + while(USB0.INTFLAGSB & USB_RMWBUSY_bm); if(USB_Endpoint_SelectedEndpoint & ENDPOINT_DIR_IN) { USB0.STATUS[USB_Endpoint_SelectedEndpoint & ENDPOINT_EPNUM_MASK].INSET = Config; @@ -466,7 +463,7 @@ ATTR_ALWAYS_INLINE static inline void Endpoint_ResetDataToggle(void) { - USB_Endpoint_ClearStatus(USB_TOGGLE_bm); + Endpoint_ClearStatus(USB_TOGGLE_bm); } /** Determines the currently selected endpoint's direction. From 041041b38abc5cfce709c55c98b06e665b646ba7 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Thu, 7 Mar 2024 09:33:23 +0100 Subject: [PATCH 17/30] Remove LowSpeed FullSpeed after buildtest fail --- BuildTests/SingleUSBModeTest/makefile | 4 ++-- LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/BuildTests/SingleUSBModeTest/makefile b/BuildTests/SingleUSBModeTest/makefile index 756b2c36e..c61789b35 100644 --- a/BuildTests/SingleUSBModeTest/makefile +++ b/BuildTests/SingleUSBModeTest/makefile @@ -44,13 +44,13 @@ compile: $(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=avr64du32u CC_FLAGS='-D USB_DEVICE_ONLY' + $(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=avr64du32u + $(MAKE) -f makefile.test clean ARCH=AVRDX MCU=avr64du32 %: diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c index e79ac9d22..a37225d80 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c @@ -154,11 +154,6 @@ static void USB_Init_Device(void) #endif #endif - if (USB_Options & USB_DEVICE_OPT_LOWSPEED) - USB_Device_SetLowSpeed(); - else - USB_Device_SetFullSpeed(); - Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, USB_Device_ControlEndpointSize, 1); From 33d50e6255619466015643ea9e6216f0c8b451bd Mon Sep 17 00:00:00 2001 From: echoromeo Date: Thu, 7 Mar 2024 09:50:04 +0100 Subject: [PATCH 18/30] DoubleSpeed --- LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h b/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h index 6a24f44de..b57c32840 100644 --- a/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h +++ b/LUFA/Drivers/Peripheral/AVRDX/Serial_AVRDX.h @@ -179,7 +179,7 @@ { 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); + 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. From 3c6a82bf6f8d570e4d0482237ab396334ffa944a Mon Sep 17 00:00:00 2001 From: echoromeo Date: Thu, 7 Mar 2024 09:51:14 +0100 Subject: [PATCH 19/30] Removing Banks --- LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c | 2 +- LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h | 6 ++---- LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c | 2 +- LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c index a90e9487f..5b634af67 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c @@ -156,7 +156,7 @@ bool Endpoint_ConfigureEndpointTable(const USB_Endpoint_Table_t* const Table, if (!(Table[i].Address)) continue; - if (!(Endpoint_ConfigureEndpoint(Table[i].Address, Table[i].Type, Table[i].Size, Table[i].Banks))) + if (!(Endpoint_ConfigureEndpoint(Table[i].Address, Table[i].Type, Table[i].Size))) { return false; } diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h index 183d46d9c..61ba8948f 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h @@ -252,12 +252,10 @@ */ static inline bool Endpoint_ConfigureEndpoint(const uint8_t Address, const uint8_t Type, - const uint16_t Size, - const uint8_t Banks) ATTR_ALWAYS_INLINE; + const uint16_t Size) ATTR_ALWAYS_INLINE; static inline bool Endpoint_ConfigureEndpoint(const uint8_t Address, const uint8_t Type, - const uint16_t Size, - const uint8_t Banks) + const uint16_t Size) { uint8_t EPConfigMask = (USB_TCDSBL_bm | Endpoint_BytesToEPSizeMask(Size)); diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c index a37225d80..c40089c84 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c @@ -155,7 +155,7 @@ static void USB_Init_Device(void) #endif Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, - USB_Device_ControlEndpointSize, 1); + USB_Device_ControlEndpointSize); USB_INT_Enable(USB_INT_BUSEVENTI); diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c index d56fbf732..731e6a888 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c @@ -97,7 +97,7 @@ ISR(USB0_BUSEVENT_vect) Endpoint_ClearEndpoints(); Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, - USB_Device_ControlEndpointSize, 1); + USB_Device_ControlEndpointSize); EVENT_USB_Device_Reset(); } From ead85aa29731068b5c9df5a176fd4d8a8a50fcf0 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Thu, 7 Mar 2024 15:30:52 +0100 Subject: [PATCH 20/30] Renamed folder to AVRDX --- LUFA/Drivers/Board/{AVR_Dx => AVRDX}/AVR64DU32_CNANO/Board.h | 0 LUFA/Drivers/Board/{AVR_Dx => AVRDX}/AVR64DU32_CNANO/Buttons.h | 0 LUFA/Drivers/Board/{AVR_Dx => AVRDX}/AVR64DU32_CNANO/LEDs.h | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename LUFA/Drivers/Board/{AVR_Dx => AVRDX}/AVR64DU32_CNANO/Board.h (100%) rename LUFA/Drivers/Board/{AVR_Dx => AVRDX}/AVR64DU32_CNANO/Buttons.h (100%) rename LUFA/Drivers/Board/{AVR_Dx => AVRDX}/AVR64DU32_CNANO/LEDs.h (100%) diff --git a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h similarity index 100% rename from LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Board.h rename to LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h diff --git a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h similarity index 100% rename from LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/Buttons.h rename to LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h diff --git a/LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h similarity index 100% rename from LUFA/Drivers/Board/AVR_Dx/AVR64DU32_CNANO/LEDs.h rename to LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h From 7c53e5076ebdbd33462149597396daa3feebddfe Mon Sep 17 00:00:00 2001 From: echoromeo Date: Thu, 7 Mar 2024 15:36:54 +0100 Subject: [PATCH 21/30] Bugfixes for making it build and run --- LUFA/Build/DMBS/DMBS/atprogram.mk | 2 +- .../DeviceTemplate/DeviceApplication.c | 2 +- LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h | 4 +++- LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c | 9 +++---- LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h | 4 ++-- .../USB/Core/AVRDX/USBController_AVRDX.c | 5 ++-- .../USB/Core/AVRDX/USBController_AVRDX.h | 8 ++----- .../USB/Core/AVRDX/USBInterrupt_AVRDX.h | 24 +++++++++++++++++++ 8 files changed, 40 insertions(+), 18 deletions(-) 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/CodeTemplates/DeviceTemplate/DeviceApplication.c b/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c index c8c028f32..bed584ce4 100644 --- a/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c +++ b/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c @@ -85,7 +85,7 @@ void SetupHardware(void) AVRDXCLK_SetCPUClockSource(CLOCK_SRC_INT_OSCHF); /* Hardware Initialization */ - USB_Init(USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH); + USB_Init(USB_OPT_USBVREG_ENABLE | USB_OPT_BUSEVENT_PRIHIGH); #endif } diff --git a/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h index a74e57d36..e593ef694 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/Device_AVRDX.h @@ -175,7 +175,9 @@ ATTR_ALWAYS_INLINE static inline void USB_Device_SetDeviceAddress(const uint8_t Address) { - USB0.ADDR = Address; + (void)Address; + + /* Use USB_Device_EnableDeviceAddress for AVR Dx */ } ATTR_ALWAYS_INLINE diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c index 5b634af67..3d24fc460 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c @@ -72,7 +72,7 @@ bool Endpoint_IsSETUPReceived(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); - if (Endpoint_GetStatus() & USB_SETUP_bm) + if (Endpoint_GetStatus() & USB_EPSETUP_bm) { USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; return true; @@ -84,11 +84,12 @@ bool Endpoint_IsSETUPReceived(void) void Endpoint_ClearSETUP(void) { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); - Endpoint_ClearStatus(USB_SETUP_bm | USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); + 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; } @@ -96,13 +97,13 @@ void Endpoint_ClearSETUP(void) void Endpoint_ClearIN(void) { USB_Endpoint_SelectedHandle->CNT = USB_Endpoint_SelectedFIFO->Position; - Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_OVF_bm); + 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_OVF_bm); + Endpoint_ClearStatus(USB_TRNCOMPL_bm | USB_BUSNAK_bm | USB_UNFOVF_bm); USB_Endpoint_SelectedFIFO->Position = 0; } diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h index 61ba8948f..745dccd52 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h @@ -262,7 +262,7 @@ if ((Address & ENDPOINT_EPNUM_MASK) >= ENDPOINT_TOTAL_ENDPOINTS) return false; - // TODO - What about ISO1023? + // TODO - What about ISO? if (Size > 64) return false; @@ -345,7 +345,7 @@ */ static inline void Endpoint_AbortPendingIN(void) { - USB_Endpoint_SelectedHandle->STATUS |= USB_BUSNAK_bm; + Endpoint_SetStatus(USB_BUSNAK_bm); } /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c index c40089c84..1993c6f82 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c @@ -44,7 +44,7 @@ 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) + 1]; +uint8_t USB_EndpointTable[sizeof(USB_EndpointTable_t)] ATTR_ALIGNED(2); void USB_Init( #if defined(USB_CAN_BE_BOTH) @@ -69,8 +69,7 @@ void USB_Init( uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); GlobalInterruptDisable(); - /* Ugly workaround to ensure an aligned table, since __BIGGEST_ALIGNMENT__ == 1 for the 8-bit AVR-GCC toolchain */ - USB0.EPPTR = ((intptr_t)&USB_EndpointTable[1] & ~(1 << 0)); + 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) diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h index bc73b0a5b..4beaa748e 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h @@ -61,17 +61,13 @@ #if defined(MAX_ENDPOINT_INDEX) #define ENDPOINT_TABLE_COUNT (MAX_ENDPOINT_INDEX + 1) #else - #define ENDPOINT_TABLE_COUNT 16 + #define ENDPOINT_TABLE_COUNT USB_EP_NUM_MAX #endif /* Type Defines: */ typedef struct { - struct - { - USB_EP_t OUT; - USB_EP_t IN; - } Endpoints[ENDPOINT_TABLE_COUNT]; + USB_EP_PAIR_t Endpoints[ENDPOINT_TABLE_COUNT]; uint16_t FrameNum; } ATTR_PACKED USB_EndpointTable_t; diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h index 4cdaf6848..83f9f1940 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.h @@ -75,6 +75,15 @@ 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; @@ -91,6 +100,15 @@ 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; @@ -128,6 +146,12 @@ { 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: From 802b8c3bd026d0cd89984b0e946488930f0cd50a Mon Sep 17 00:00:00 2001 From: echoromeo Date: Thu, 7 Mar 2024 16:08:18 +0100 Subject: [PATCH 22/30] Added AVRDX to all LUFAConfig.h with support for XMEGA --- .../ClassDriver/CCID/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../ClassDriver/DualMIDI/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../DualVirtualSerial/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../GenericHID/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../ClassDriver/Joystick/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../ClassDriver/Keyboard/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../KeyboardMouse/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../Config/LUFAConfig.h | 33 +++++++++++++++++++ .../ClassDriver/MIDI/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../MassStorage/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../MassStorageKeyboard/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../ClassDriver/Mouse/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../RNDISEthernet/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../VirtualSerial/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../Config/LUFAConfig.h | 33 +++++++++++++++++++ .../VirtualSerialMouse/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../TestAndMeasurement/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../LowLevel/BulkVendor/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../Device/LowLevel/CCID/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../DualVirtualSerial/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../LowLevel/GenericHID/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../LowLevel/Joystick/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../LowLevel/Keyboard/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../KeyboardMouse/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../Device/LowLevel/MIDI/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../LowLevel/MassStorage/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../Device/LowLevel/Mouse/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../RNDISEthernet/Config/LUFAConfig.h | 33 +++++++++++++++++++ .../VirtualSerial/Config/LUFAConfig.h | 33 +++++++++++++++++++ 29 files changed, 957 insertions(+) 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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 From 3e47efcb2ac71b6029e2b2d61a9a94fe4bc731c2 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Thu, 7 Mar 2024 16:14:56 +0100 Subject: [PATCH 23/30] Added AVR Dx to SetupHardware for all Device demos with XMEGA support --- Demos/Device/ClassDriver/CCID/CCID.c | 4 ++++ Demos/Device/ClassDriver/DualMIDI/DualMIDI.c | 4 ++++ .../Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c | 4 ++++ Demos/Device/ClassDriver/GenericHID/GenericHID.c | 4 ++++ Demos/Device/ClassDriver/Joystick/Joystick.c | 4 ++++ Demos/Device/ClassDriver/Keyboard/Keyboard.c | 4 ++++ Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c | 4 ++++ .../KeyboardMouseMultiReport/KeyboardMouseMultiReport.c | 4 ++++ Demos/Device/ClassDriver/MIDI/MIDI.c | 4 ++++ Demos/Device/ClassDriver/MassStorage/MassStorage.c | 4 ++++ .../ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c | 4 ++++ Demos/Device/ClassDriver/Mouse/Mouse.c | 4 ++++ Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.c | 4 ++++ Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c | 4 ++++ .../VirtualSerialMassStorage/VirtualSerialMassStorage.c | 4 ++++ .../ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c | 4 ++++ .../Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c | 4 ++++ Demos/Device/LowLevel/BulkVendor/BulkVendor.c | 4 ++++ Demos/Device/LowLevel/CCID/CCID.c | 4 ++++ Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c | 4 ++++ Demos/Device/LowLevel/GenericHID/GenericHID.c | 4 ++++ Demos/Device/LowLevel/Joystick/Joystick.c | 4 ++++ Demos/Device/LowLevel/Keyboard/Keyboard.c | 4 ++++ Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c | 4 ++++ Demos/Device/LowLevel/MIDI/MIDI.c | 4 ++++ Demos/Device/LowLevel/MassStorage/MassStorage.c | 4 ++++ Demos/Device/LowLevel/Mouse/Mouse.c | 4 ++++ Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c | 4 ++++ Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c | 4 ++++ 29 files changed, 116 insertions(+) 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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 */ From 17d0667d6b76d4f7408aafd19e0806e6b4f72bf6 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 8 Mar 2024 09:58:13 +0100 Subject: [PATCH 24/30] Missing Buttons_GetStatus from BOARD_NONE --- LUFA/Drivers/Board/Buttons.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LUFA/Drivers/Board/Buttons.h b/LUFA/Drivers/Board/Buttons.h index 0b5070ca2..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) From 4a50a9d6f2b09a724cac7ceb438b7c33b2114a88 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 8 Mar 2024 09:58:47 +0100 Subject: [PATCH 25/30] Added !defined(BOARD_HAS_x to BOARD_NONE --- LUFA/Drivers/Board/Buttons.h | 2 +- LUFA/Drivers/Board/Joystick.h | 2 +- LUFA/Drivers/Board/LEDs.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LUFA/Drivers/Board/Buttons.h b/LUFA/Drivers/Board/Buttons.h index 2d6f7bbb7..e5ce3e33e 100644 --- a/LUFA/Drivers/Board/Buttons.h +++ b/LUFA/Drivers/Board/Buttons.h @@ -91,7 +91,7 @@ /* Includes: */ #include "../../Common/Common.h" - #if (BOARD == BOARD_NONE) + #if ((BOARD == BOARD_NONE) || !defined(BOARD_HAS_BUTTONS)) #define BUTTONS_BUTTON1 0 static inline void Buttons_Init(void) {} static inline void Buttons_Disable(void) {} diff --git a/LUFA/Drivers/Board/Joystick.h b/LUFA/Drivers/Board/Joystick.h index 5d69d4e17..73e7e5d80 100644 --- a/LUFA/Drivers/Board/Joystick.h +++ b/LUFA/Drivers/Board/Joystick.h @@ -99,7 +99,7 @@ /* Includes: */ #include "../../Common/Common.h" - #if (BOARD == BOARD_NONE) + #if ((BOARD == BOARD_NONE) || !defined(BOARD_HAS_JOYSTICK)) #define JOY_UP 0 #define JOY_DOWN 0 #define JOY_LEFT 0 diff --git a/LUFA/Drivers/Board/LEDs.h b/LUFA/Drivers/Board/LEDs.h index c7a8f55cb..de6b0c5ec 100644 --- a/LUFA/Drivers/Board/LEDs.h +++ b/LUFA/Drivers/Board/LEDs.h @@ -107,7 +107,7 @@ /* Includes: */ #include "../../Common/Common.h" - #if (BOARD == BOARD_NONE) + #if ((BOARD == BOARD_NONE) || !defined(BOARD_HAS_LEDS)) static inline void LEDs_Init(void) {} static inline void LEDs_Disable(void) {} static inline void LEDs_TurnOnLEDs(const uint_reg_t LEDMask) {} From 2fee4fa222aec5ea3f5937816ef2570368411c5c Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 8 Mar 2024 11:16:28 +0100 Subject: [PATCH 26/30] Reverting the include stuff --- LUFA/Drivers/Board/Buttons.h | 2 +- LUFA/Drivers/Board/Joystick.h | 2 +- LUFA/Drivers/Board/LEDs.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LUFA/Drivers/Board/Buttons.h b/LUFA/Drivers/Board/Buttons.h index e5ce3e33e..2d6f7bbb7 100644 --- a/LUFA/Drivers/Board/Buttons.h +++ b/LUFA/Drivers/Board/Buttons.h @@ -91,7 +91,7 @@ /* Includes: */ #include "../../Common/Common.h" - #if ((BOARD == BOARD_NONE) || !defined(BOARD_HAS_BUTTONS)) + #if (BOARD == BOARD_NONE) #define BUTTONS_BUTTON1 0 static inline void Buttons_Init(void) {} static inline void Buttons_Disable(void) {} diff --git a/LUFA/Drivers/Board/Joystick.h b/LUFA/Drivers/Board/Joystick.h index 73e7e5d80..5d69d4e17 100644 --- a/LUFA/Drivers/Board/Joystick.h +++ b/LUFA/Drivers/Board/Joystick.h @@ -99,7 +99,7 @@ /* Includes: */ #include "../../Common/Common.h" - #if ((BOARD == BOARD_NONE) || !defined(BOARD_HAS_JOYSTICK)) + #if (BOARD == BOARD_NONE) #define JOY_UP 0 #define JOY_DOWN 0 #define JOY_LEFT 0 diff --git a/LUFA/Drivers/Board/LEDs.h b/LUFA/Drivers/Board/LEDs.h index de6b0c5ec..c7a8f55cb 100644 --- a/LUFA/Drivers/Board/LEDs.h +++ b/LUFA/Drivers/Board/LEDs.h @@ -107,7 +107,7 @@ /* Includes: */ #include "../../Common/Common.h" - #if ((BOARD == BOARD_NONE) || !defined(BOARD_HAS_LEDS)) + #if (BOARD == BOARD_NONE) static inline void LEDs_Init(void) {} static inline void LEDs_Disable(void) {} static inline void LEDs_TurnOnLEDs(const uint_reg_t LEDMask) {} From ceec16c2c5a20a1d0a349b930077cd07feab576c Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 8 Mar 2024 11:16:58 +0100 Subject: [PATCH 27/30] Comments and pinconfig --- LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h | 2 +- LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h | 6 ++++-- LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h index dd0711229..d9a6a8273 100644 --- a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h +++ b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Board.h @@ -29,7 +29,7 @@ */ /** \file - * \brief Board specific information header for the x. + * \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 diff --git a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h index 98dd4ccb2..2dc4eaab6 100644 --- a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h +++ b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/Buttons.h @@ -76,13 +76,15 @@ static inline void Buttons_Init(void) { PORTF.OUTCLR = BUTTONS_BUTTON1; - PORTF.PIN6CTRL = (PORT_PULLUPEN_bm | PORT_INVEN_bm); + PORTF.PINCONFIG = (PORT_PULLUPEN_bm | PORT_INVEN_bm); + PORTF.PINCTRLUPD = BUTTONS_BUTTON1; } static inline void Buttons_Disable(void) { PORTF.OUTCLR = BUTTONS_BUTTON1; - PORTF.PIN6CTRL = 0; + PORTF.PINCONFIG = 0; + PORTF.PINCTRLUPD = BUTTONS_BUTTON1; } ATTR_WARN_UNUSED_RESULT diff --git a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h index 40c34a8c9..94021e58b 100644 --- a/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h +++ b/LUFA/Drivers/Board/AVRDX/AVR64DU32_CNANO/LEDs.h @@ -90,7 +90,8 @@ PORTF.DIRSET = LEDS_PORTF_LEDS; PORTF.OUTCLR = LEDS_PORTF_LEDS; - PORTF.PIN2CTRL = PORT_INVEN_bm; + PORTF.PINCONFIG = PORT_INVEN_bm; + PORTF.PINCTRLUPD = LEDS_PORTF_LEDS; } static inline void LEDs_Disable(void) @@ -98,7 +99,8 @@ PORTF.DIRCLR = LEDS_PORTF_LEDS; PORTF.OUTCLR = LEDS_PORTF_LEDS; - PORTF.PIN2CTRL = 0; + PORTF.PINCONFIG = 0; + PORTF.PINCTRLUPD = LEDS_PORTF_LEDS; } static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) @@ -134,7 +136,7 @@ ATTR_WARN_UNUSED_RESULT static inline uint8_t LEDs_GetLEDs(void) { - return (PORTF_OUT & LEDS_PORTF_LEDS); + return (PORTF.OUT & LEDS_PORTF_LEDS); } #endif From a0a614aadd43191f2eae89cf2a7bfae7257711f4 Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 8 Mar 2024 11:17:23 +0100 Subject: [PATCH 28/30] Reverting Banks --- LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c | 2 +- LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h | 11 ++++++++--- LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c | 2 +- LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c index 3d24fc460..bc2c1a323 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.c @@ -157,7 +157,7 @@ bool Endpoint_ConfigureEndpointTable(const USB_Endpoint_Table_t* const Table, if (!(Table[i].Address)) continue; - if (!(Endpoint_ConfigureEndpoint(Table[i].Address, Table[i].Type, Table[i].Size))) + if (!(Endpoint_ConfigureEndpoint(Table[i].Address, Table[i].Type, Table[i].Size, Table[i].Banks))) { return false; } diff --git a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h index 745dccd52..3185d3cb1 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/Endpoint_AVRDX.h @@ -240,7 +240,8 @@ * the endpoint's data direction). The bank size must indicate the maximum packet size * that the endpoint can handle. * - * \param[in] Banks Number of hardware banks to use for the endpoint being configured. + * \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. @@ -252,11 +253,15 @@ */ static inline bool Endpoint_ConfigureEndpoint(const uint8_t Address, const uint8_t Type, - const uint16_t Size) ATTR_ALWAYS_INLINE; + 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 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) diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c index 1993c6f82..5a27f81a0 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.c @@ -154,7 +154,7 @@ static void USB_Init_Device(void) #endif Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, - USB_Device_ControlEndpointSize); + USB_Device_ControlEndpointSize, 1); USB_INT_Enable(USB_INT_BUSEVENTI); diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c index 731e6a888..d56fbf732 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c +++ b/LUFA/Drivers/USB/Core/AVRDX/USBInterrupt_AVRDX.c @@ -97,7 +97,7 @@ ISR(USB0_BUSEVENT_vect) Endpoint_ClearEndpoints(); Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, - USB_Device_ControlEndpointSize); + USB_Device_ControlEndpointSize, 1); EVENT_USB_Device_Reset(); } From 93bd84987e88f8dc83585f3f99789d0110a19d8d Mon Sep 17 00:00:00 2001 From: echoromeo Date: Fri, 8 Mar 2024 12:58:26 +0100 Subject: [PATCH 29/30] Added DU as compatible --- Demos/Device/ClassDriver/CCID/CCID.txt | 1 + Demos/Device/ClassDriver/DualMIDI/DualMIDI.txt | 1 + Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt | 1 + Demos/Device/ClassDriver/GenericHID/GenericHID.txt | 1 + Demos/Device/ClassDriver/Joystick/Joystick.txt | 1 + Demos/Device/ClassDriver/Keyboard/Keyboard.txt | 1 + Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.txt | 1 + .../KeyboardMouseMultiReport/KeyboardMouseMultiReport.txt | 1 + Demos/Device/ClassDriver/MIDI/MIDI.txt | 1 + Demos/Device/ClassDriver/MassStorage/MassStorage.txt | 1 + .../ClassDriver/MassStorageKeyboard/MassStorageKeyboard.txt | 1 + Demos/Device/ClassDriver/Mouse/Mouse.txt | 1 + Demos/Device/ClassDriver/RNDISEthernet/RNDISEthernet.txt | 1 + Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt | 1 + .../VirtualSerialMassStorage/VirtualSerialMassStorage.txt | 1 + .../Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt | 1 + Demos/Device/LowLevel/BulkVendor/BulkVendor.txt | 1 + Demos/Device/LowLevel/CCID/CCID.txt | 1 + Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt | 1 + Demos/Device/LowLevel/GenericHID/GenericHID.txt | 1 + Demos/Device/LowLevel/Joystick/Joystick.txt | 1 + Demos/Device/LowLevel/Keyboard/Keyboard.txt | 1 + Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.txt | 1 + Demos/Device/LowLevel/MIDI/MIDI.txt | 1 + Demos/Device/LowLevel/MassStorage/MassStorage.txt | 1 + Demos/Device/LowLevel/Mouse/Mouse.txt | 1 + Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.txt | 1 + Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt | 1 + 28 files changed, 28 insertions(+) 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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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: * From 2c319565df9e526188cdae76af99595cfc14af3c Mon Sep 17 00:00:00 2001 From: echoromeo Date: Tue, 10 Sep 2024 08:46:06 +0200 Subject: [PATCH 30/30] ENDPOINT_TABLE_COUNT= USB_MAX_ENDPOINTS --- LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h index 4beaa748e..07d5088af 100644 --- a/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h +++ b/LUFA/Drivers/USB/Core/AVRDX/USBController_AVRDX.h @@ -61,7 +61,7 @@ #if defined(MAX_ENDPOINT_INDEX) #define ENDPOINT_TABLE_COUNT (MAX_ENDPOINT_INDEX + 1) #else - #define ENDPOINT_TABLE_COUNT USB_EP_NUM_MAX + #define ENDPOINT_TABLE_COUNT USB_MAX_ENDPOINTS #endif /* Type Defines: */