Update all demos, projects and bootloaders to indent all function parameters, one...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Pipe.h
index da296dc..ee43bab 100644 (file)
                        #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
                                #define __CALLBACK_PARAM     , StreamCallbackPtr_t Callback
                        #else
-                               #define __CALLBACK_PARAM                        
+                               #define __CALLBACK_PARAM
                        #endif
 
                        /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the
                         *
                         *  \return Boolean true if the configuration is successful, false otherwise.
                         */
-                       bool Pipe_ConfigurePipe(const uint8_t  Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,
-                                               const uint16_t Size, const uint8_t Banks);
+                       bool Pipe_ConfigurePipe(const uint8_t  Number,
+                                               const uint8_t Type,
+                                               const uint8_t Token,
+                                               const uint8_t EndpointNumber,
+                                               const uint16_t Size,
+                                               const uint8_t Banks);
 
                        /** Spin-loops until the currently selected non-control pipe is ready for the next packed of data to be read 
                         *  or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Discard_Stream(uint16_t Length __CALLBACK_PARAM);
+                       uint8_t Pipe_Discard_Stream(uint16_t Length
+                                                   __CALLBACK_PARAM);
 
                        /** Writes the given number of bytes to the pipe from the given buffer in little endian,
                         *  sending full packets to the device as needed. The last packet filled is not automatically sent;
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Write_Stream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);                            
+                       uint8_t Pipe_Write_Stream_LE(const void* Buffer,
+                                                    uint16_t Length
+                                                    __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
 
                        /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE().
                         *
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Write_EStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       uint8_t Pipe_Write_EStream_LE(const void* Buffer,
+                                                     uint16_t Length
+                                                     __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
                        
                        /** FLASH buffer source version of \ref Pipe_Write_Stream_LE().
                         *
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Write_PStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-                                               
+                       uint8_t Pipe_Write_PStream_LE(const void* Buffer,
+                                                     uint16_t Length
+                                                     __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       
                        /** Writes the given number of bytes to the pipe from the given buffer in big endian,
                         *  sending full packets to the device as needed. The last packet filled is not automatically sent;
                         *  the user is responsible for manually sending the last written packet to the host via the
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Write_Stream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       uint8_t Pipe_Write_Stream_BE(const void* Buffer,
+                                                    uint16_t Length
+                                                    __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
 
                        /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE().
                         *
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Write_EStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       uint8_t Pipe_Write_EStream_BE(const void* Buffer,
+                                                     uint16_t Length
+                                                     __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
                        
                        /** FLASH buffer source version of \ref Pipe_Write_Stream_BE().
                         *
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Write_PStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       uint8_t Pipe_Write_PStream_BE(const void* Buffer,
+                                                     uint16_t Length
+                                                     __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
 
                        /** Reads the given number of bytes from the pipe into the given buffer in little endian,
                         *  sending full packets to the device as needed. The last packet filled is not automatically sent;
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       uint8_t Pipe_Read_Stream_LE(void* Buffer,
+                                                   uint16_t Length
+                                                   __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
 
                        /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE().
                         *
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Read_EStream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       uint8_t Pipe_Read_EStream_LE(void* Buffer,
+                                                    uint16_t Length
+                                                    __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
 
                        /** Reads the given number of bytes from the pipe into the given buffer in big endian,
                         *  sending full packets to the device as needed. The last packet filled is not automatically sent;
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       uint8_t Pipe_Read_Stream_BE(void* Buffer,
+                                                   uint16_t Length
+                                                   __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
                        
                        /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE().
                         *
                         *
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
                         */
-                       uint8_t Pipe_Read_EStream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+                       uint8_t Pipe_Read_EStream_BE(void* Buffer,
+                                                    uint16_t Length
+                                                    __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
 
        /* Private Interface - For use in library only: */
        #if !defined(__DOXYGEN__)
                        void Pipe_ClearPipes(void);
 
                /* Inline Functions: */
-                       static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
-                       static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes)
+                       static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
+                       static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes)
                        {
-                               if (Bytes <= 8)
-                                 return (0 << EPSIZE0);
-                               else if (Bytes <= 16)
-                                 return (1 << EPSIZE0);
-                               else if (Bytes <= 32)
-                                 return (2 << EPSIZE0);
-                               else if (Bytes <= 64)
-                                 return (3 << EPSIZE0);
-                               else if (Bytes <= 128)
-                                 return (4 << EPSIZE0);
-                               else
-                                 return (5 << EPSIZE0);
+                               uint8_t  MaskVal    = 0;
+                               uint16_t CheckBytes = 8;
+                               
+                               while ((CheckBytes < Bytes) && (CheckBytes < PIPE_MAX_SIZE))
+                               {
+                                       MaskVal++;
+                                       CheckBytes <<= 1;
+                               }
+                               
+                               return (MaskVal << EPSIZE0);
                        }
 
        #endif