More porting of the USB core to the AVR32.
[pub/lufa.git] / LUFA / Drivers / USB / LowLevel / Pipe.h
index 08935e1..fca44d8 100644 (file)
@@ -86,6 +86,7 @@
                #endif\r
 \r
                #include "../../../Common/Common.h"\r
+               #include "LowLevel.h"\r
                #include "../HighLevel/USBTask.h"\r
 \r
                #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)\r
 \r
        /* Preprocessor Checks: */\r
                #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
-                       #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.\r
+                       #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
                #endif\r
                \r
        /* Public Interface - May be used in end-application: */\r
                        static inline uint8_t Pipe_Read_Byte(void)\r
                        {\r
                                #if defined(__AVR32__)\r
-                               return 0; // TODO\r
+                               return __AVR32_EPREG_X(UEDAT0);\r
                                #elif defined(__AVR__)\r
                                return UPDATX;\r
                                #endif\r
                        static inline void Pipe_Write_Byte(const uint8_t Byte)\r
                        {\r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               __AVR32_EPREG_X(UEDAT0) = Byte;\r
                                #elif defined(__AVR__)\r
                                UPDATX = Byte;\r
                                #endif\r
                                uint8_t Dummy;\r
                                \r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               Dummy = __AVR32_EPREG_X(UEDAT0);\r
                                #elif defined(__AVR__)\r
                                Dummy = UPDATX;\r
                                #endif\r
                                } Data;\r
                                \r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0);\r
+                               Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0);\r
                                #elif defined(__AVR__)\r
                                Data.Bytes[0] = UPDATX;\r
                                Data.Bytes[1] = UPDATX;\r
                                } Data;\r
                                \r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0);\r
+                               Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0);\r
                                #elif defined(__AVR__)\r
                                Data.Bytes[1] = UPDATX;\r
                                Data.Bytes[0] = UPDATX;\r
                        static inline void Pipe_Write_Word_LE(const uint16_t Word)\r
                        {\r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               __AVR32_EPREG_X(UEDAT0) = (Word & 0xFF);\r
+                               __AVR32_EPREG_X(UEDAT0) = (Word >> 8);\r
                                #elif defined(__AVR__)\r
                                UPDATX = (Word & 0xFF);\r
                                UPDATX = (Word >> 8);\r
                        static inline void Pipe_Write_Word_BE(const uint16_t Word)\r
                        {\r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               __AVR32_EPREG_X(UEDAT0) = (Word >> 8);\r
+                               __AVR32_EPREG_X(UEDAT0) = (Word & 0xFF);\r
                                #elif defined(__AVR__)\r
                                UPDATX = (Word >> 8);\r
                                UPDATX = (Word & 0xFF);\r
                                uint8_t Dummy;\r
                                \r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               Dummy = __AVR32_EPREG_X(UEDAT0);\r
+                               Dummy = __AVR32_EPREG_X(UEDAT0);\r
                                #elif defined(__AVR__)\r
                                Dummy = UPDATX;\r
                                Dummy = UPDATX;\r
                                } Data;\r
                                \r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0);\r
+                               Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0);\r
+                               Data.Bytes[2] = __AVR32_EPREG_X(UEDAT0);\r
+                               Data.Bytes[3] = __AVR32_EPREG_X(UEDAT0);\r
                                #elif defined(__AVR__)\r
                                Data.Bytes[0] = UPDATX;\r
                                Data.Bytes[1] = UPDATX;\r
                                } Data;\r
                                \r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               Data.Bytes[3] = __AVR32_EPREG_X(UEDAT0);\r
+                               Data.Bytes[2] = __AVR32_EPREG_X(UEDAT0);\r
+                               Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0);\r
+                               Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0);\r
                                #elif defined(__AVR__)\r
                                Data.Bytes[3] = UPDATX;\r
                                Data.Bytes[2] = UPDATX;\r
                                Data.Bytes[1] = UPDATX;\r
                                Data.Bytes[0] = UPDATX;\r
+                               #endif\r
                        \r
                                return Data.DWord;\r
                        }\r
                        static inline void Pipe_Write_DWord_LE(const uint32_t DWord)\r
                        {\r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               __AVR32_EPREG_X(UEDAT0) = (DWord &  0xFF);\r
+                               __AVR32_EPREG_X(UEDAT0) = (DWord >> 8);\r
+                               __AVR32_EPREG_X(UEDAT0) = (DWord >> 16);\r
+                               __AVR32_EPREG_X(UEDAT0) = (DWord >> 24);\r
                                #elif defined(__AVR__)\r
                                UPDATX = (DWord &  0xFF);\r
                                UPDATX = (DWord >> 8);\r
                        static inline void Pipe_Write_DWord_BE(const uint32_t DWord)\r
                        {\r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               __AVR32_EPREG_X(UEDAT0) = (DWord >> 24);\r
+                               __AVR32_EPREG_X(UEDAT0) = (DWord >> 16);\r
+                               __AVR32_EPREG_X(UEDAT0) = (DWord >> 8);\r
+                               __AVR32_EPREG_X(UEDAT0) = (DWord &  0xFF);\r
                                #elif defined(__AVR__)\r
                                UPDATX = (DWord >> 24);\r
                                UPDATX = (DWord >> 16);\r
                                uint8_t Dummy;\r
                                \r
                                #if defined(__AVR32__)\r
-                               // TODO\r
+                               Dummy = __AVR32_EPREG_X(UEDAT0);\r
+                               Dummy = __AVR32_EPREG_X(UEDAT0);\r
+                               Dummy = __AVR32_EPREG_X(UEDAT0);\r
+                               Dummy = __AVR32_EPREG_X(UEDAT0);\r
                                #elif defined(__AVR__)\r
                                Dummy = UPDATX;\r
                                Dummy = UPDATX;\r
                         *  \param[in] Length    Number of bytes to read for the currently selected pipe into the buffer.\r
                         *  \param[in] Callback  Name of a callback routine to call between successive USB packet transfers, NULL if no callback\r
                         *\r
+                        *  \note Not available on AVR32 UC3B targets.\r
+                        *\r
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
                         */\r
                        uint8_t Pipe_Write_EStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);\r
                         *  \param[in] Length    Number of bytes to read for the currently selected pipe into the buffer.\r
                         *  \param[in] Callback  Name of a callback routine to call between successive USB packet transfers, NULL if no callback\r
                         *\r
+                        *  \note Not available on AVR32 UC3B targets.\r
+                        *\r
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
                         */\r
                        uint8_t Pipe_Write_EStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);\r
                         *  \param[in] Length    Number of bytes to read for the currently selected pipe to read from.\r
                         *  \param[in] Callback  Name of a callback routine to call between successive USB packet transfers, NULL if no callback\r
                         *\r
+                        *  \note Not available on AVR32 UC3B targets.\r
+                        *\r
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
                         */\r
                        uint8_t Pipe_Read_EStream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);\r
                         *  \param[in] Length    Number of bytes to read for the currently selected pipe to read from.\r
                         *  \param[in] Callback  Name of a callback routine to call between successive USB packet transfers, NULL if no callback\r
                         *\r
+                        *  \note Not available on AVR32 UC3B targets.\r
+                        *\r
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
                         */\r
                        uint8_t Pipe_Read_EStream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);\r
                        void Pipe_ClearPipes(void);\r
 \r
                /* Inline Functions: */\r
-                       static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;\r
-                       static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes)\r
+                       static inline uintN_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;\r
+                       static inline uintN_t Pipe_BytesToEPSizeMask(uint16_t Bytes)\r
                        {\r
+                               #if defined(__AVR32__)\r
+                               // TODO\r
+                               return 0;\r
+                               #elif defined(__AVR__)\r
                                if (Bytes <= 8)\r
                                  return (0 << EPSIZE0);\r
                                else if (Bytes <= 16)\r
                                  return (4 << EPSIZE0);\r
                                else\r
                                  return (5 << EPSIZE0);\r
+                               #endif\r
                        }\r
 \r
        #endif\r