Oops - revert changes to the Device mode Class Driver VirtualSerial demo makefile.
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Device.h
index 02dd8cf..2f54d1d 100644 (file)
 #define __USBDEVICE_H__
 
        /* Includes: */
+               #include <avr/io.h>
                #include <avr/pgmspace.h>
                #include <avr/eeprom.h>
 
                #include "../../../Common/Common.h"     
                #include "../HighLevel/StdDescriptors.h"
+               #include "USBInterrupt.h"
                #include "Endpoint.h"
 
        /* Preprocessor Checks: */
                                 *  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\n
+                                *        \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 standard.
+                                *        when running in low speed mode - refer to the USB 2.0 specification.
                                 */
                                #define USB_DEVICE_OPT_LOWSPEED            (1 << 0)
                        #endif
                         *        issued if the host is currently allowing remote wakeup events from the device (i.e.,
                         *        the \ref USB_RemoteWakeupEnabled flag is set). When the NO_DEVICE_REMOTE_WAKEUP compile
                         *        time option is used, this macro is unavailable.
-                        *        \n
+                        *        \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
                         *  \see \ref Group_Descriptors for more information on the RMWAKEUP feature and device descriptors.
                         */
                        void USB_Device_SendRemoteWakeup(void);
-                                                       
-               /* Pseudo-Function Macros: */
-                       #if defined(__DOXYGEN__)                                
-                               /** 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.
-                                */
-                               static inline bool USB_Device_EnableSOFEvents(void);
-                               
-                               /** Disables the device mode Start Of Frame events. When disabled, this stop the firing of the
-                                *  \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
-                                */
-                               static inline bool USB_Device_DisableSOFEvents(void);
-                       #else
-                               #define USB_Device_EnableSOFEvents()    MACROS{ USB_INT_Enable(USB_INT_SOFI); }MACROE
-
-                               #define USB_Device_DisableSOFEvents()   MACROS{ USB_INT_Disable(USB_INT_SOFI); }MACROE
-                       #endif
                        
                /* Type Defines: */
                        enum USB_Device_States_t
                                                                                */
                        };
                        
+               /* 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.
+                        */
+                       static inline uint16_t USB_Device_GetFrameNumber(void)
+                       {
+                               return UDFNUM;
+                       }
+               
+                       /** 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.
+                        */
+                       static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
+                       static inline void USB_Device_EnableSOFEvents(void)
+                       {
+                               USB_INT_Enable(USB_INT_SOFI);
+                       }
+                               
+                       /** 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.
+                        */
+                       static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
+                       static inline void USB_Device_DisableSOFEvents(void)
+                       {
+                               USB_INT_Disable(USB_INT_SOFI);
+                       }
+                       
                /* Function Prototypes: */
                        /** Function to retrieve a given descriptor's size and memory location from the given descriptor type value,
                         *  index and language ID. This function MUST be overridden in the user application (added with full, identical  
                         *
                         *  \return Size in bytes of the descriptor if it exists, zero or \ref NO_DESCRIPTOR otherwise.
                         */
-                       uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress
+                       uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
+                                                           const uint8_t wIndex,
+                                                           const void** const DescriptorAddress
                        #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)
                                                            , uint8_t* MemoryAddressSpace
-                       #endif                  
-                                                           )
-                                                                                   ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
+                       #endif
+                                                           ) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
 
        /* Private Interface - For use in library only: */
        #if !defined(__DOXYGEN__)
-               /* Macros: */           
-                       #define USB_Device_SetLowSpeed()          MACROS{ UDCON |=  (1 << LSM);   }MACROE
-                       #define USB_Device_SetFullSpeed()         MACROS{ UDCON &= ~(1 << LSM);   }MACROE
+               /* Inline Functions: */
+                       #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
+                       static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
+                       static inline void USB_Device_SetLowSpeed(void)
+                       {
+                               UDCON |=  (1 << LSM);
+                       }
                        
-                       #define USB_Device_SetDeviceAddress(addr) MACROS{ UDADDR = ((1 << ADDEN) | (addr & 0x7F)); }MACROE
+                       static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
+                       static inline void USB_Device_SetFullSpeed(void)
+                       {
+                               UDCON &= ~(1 << LSM);
+                       }
+                       #endif
                        
+                       static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
+                       static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
+                       {
+                               UDADDR  = ((UDADDR & (1 << ADDEN)) | (Address & 0x7F));
+                               UDADDR |= (1 << ADDEN);
+                       }
+
+                       static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE;
+                       static inline bool USB_Device_IsAddressSet(void)
+                       {
+                               return (UDADDR & (1 << ADDEN));
+                       }
        #endif
 
 #endif