Be doubly-certain that the incomming CDC class driver's endpoint/pipe is flushed...
[pub/USBasp.git] / LUFA / Drivers / Peripheral / AVRU4U6U7 / ADC.h
index 3824145..100f2c1 100644 (file)
@@ -1,21 +1,21 @@
 /*\r
              LUFA Library\r
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
 \r
                        /** Sets the ADC input clock to prescale by a factor of 128 the AVR's system clock. */\r
                        #define  ADC_PRESCALE_128                ((1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0))\r
 \r
                        /** Sets the ADC input clock to prescale by a factor of 128 the AVR's system clock. */\r
                        #define  ADC_PRESCALE_128                ((1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0))\r
+                       \r
+                       //@{\r
+                       /** MUX mask define for the ADC0 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading. */\r
+                       #define  ADC_CHANNEL0                    0x00\r
+\r
+                       /** MUX mask define for the ADC1 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading. */\r
+                       #define  ADC_CHANNEL1                    0x01\r
+\r
+                       #if !(defined(__AVR_ATmega16U4__)  || defined(__AVR_ATmega32U4__) || defined(__DOXYGEN__))\r
+                               /** MUX mask define for the ADC2 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_CHANNEL2                    0x02\r
+\r
+                               /** MUX mask define for the ADC3 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_CHANNEL3                    0x03\r
+                       #endif\r
 \r
 \r
+                       /** MUX mask define for the ADC4 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading. */\r
+                       #define  ADC_CHANNEL4                    0x04\r
+\r
+                       /** MUX mask define for the ADC5 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading. */\r
+                       #define  ADC_CHANNEL5                    0x05\r
+\r
+                       /** MUX mask define for the ADC6 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading. */\r
+                       #define  ADC_CHANNEL6                    0x06\r
+\r
+                       /** MUX mask define for the ADC7 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading. */\r
+                       #define  ADC_CHANNEL7                    0x07\r
+\r
+                       /** MUX mask define for the internal 1.1V bandgap channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading. */\r
+                       #define  ADC_1100MV_BANDGAP              0x1E\r
+                       \r
+                       #if (defined(__AVR_ATmega16U4__)  || defined(__AVR_ATmega32U4__) || defined(__DOXYGEN__))\r
+                               /** MUX mask define for the ADC8 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_CHANNEL8                0x20\r
+\r
+                               /** MUX mask define for the ADC9 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_CHANNEL9                0x21\r
+\r
+                               /** MUX mask define for the ADC10 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_CHANNEL10               0x22\r
+\r
+                               /** MUX mask define for the ADC11 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_CHANNEL11               0x23\r
+\r
+                               /** MUX mask define for the ADC12 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_CHANNEL12               0x24\r
+\r
+                               /** MUX mask define for the ADC13 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_CHANNEL13               0x25\r
+\r
+                               /** MUX mask define for the internal temperature sensor channel of the ADC. See \ref ADC_StartReading and\r
+                                *  \ref ADC_GetChannelReading.\r
+                                *\r
+                                *  \note Note available on all AVR models.\r
+                                */\r
+                               #define  ADC_INT_TEMP_SENS           0x27                       \r
+                       #endif\r
+                       //@}\r
+               \r
                /* Pseudo-Function Macros: */\r
                        #if defined(__DOXYGEN__)\r
                                /** Initializes the ADC, ready for conversions. This must be called before any other ADC operations.\r
                /* Pseudo-Function Macros: */\r
                        #if defined(__DOXYGEN__)\r
                                /** Initializes the ADC, ready for conversions. This must be called before any other ADC operations.\r
                                \r
                                #define  ADC_GetStatus()               ((ADCSRA & (1 << ADEN)) ? true : false)\r
 \r
                                \r
                                #define  ADC_GetStatus()               ((ADCSRA & (1 << ADEN)) ? true : false)\r
 \r
-                               #define  ADC_IsReadingComplete()         (!(ADCSRA & (1 << ADSC)))\r
+                               #define  ADC_IsReadingComplete()        (ADCSRA & (1 << ADSC))\r
                                \r
                                #define  ADC_GetResult()                 ADC                    \r
                        #endif\r
                                \r
                                #define  ADC_GetResult()                 ADC                    \r
                        #endif\r
                         *  associated port pin as an input and disables the digital portion of the I/O to reduce\r
                         *  power consumption.\r
                         *\r
                         *  associated port pin as an input and disables the digital portion of the I/O to reduce\r
                         *  power consumption.\r
                         *\r
+                        *  \note This must only be called for ADC channels with are connected to a physical port\r
+                        *        pin of the AVR, denoted by its special alternative function ADCx.\r
+                        *\r
+                        *  \note The channel number must be specified as an integer, and NOT a ADC_CHANNELx mask.\r
+                        *\r
                         *  \param[in] Channel  ADC channel number to set up for conversions\r
                         */\r
                        static inline void ADC_SetupChannel(const uint8_t Channel)\r
                         *  \param[in] Channel  ADC channel number to set up for conversions\r
                         */\r
                        static inline void ADC_SetupChannel(const uint8_t Channel)\r
                         *  Once executed, the conversion status can be determined via the \ref ADC_IsReadingComplete() macro and\r
                         *  the result read via the \ref ADC_GetResult() macro.\r
                         *\r
                         *  Once executed, the conversion status can be determined via the \ref ADC_IsReadingComplete() macro and\r
                         *  the result read via the \ref ADC_GetResult() macro.\r
                         *\r
-                        *  \param[in] MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
+                        *  \param[in] MUXMask  Mask comprising of an ADC channel mask, reference mask and adjustment mask\r
                         */\r
                        static inline void ADC_StartReading(const uint8_t MUXMask)\r
                        {\r
                         */\r
                        static inline void ADC_StartReading(const uint8_t MUXMask)\r
                        {\r
                                ADCSRA |= (1 << ADSC);\r
                        }\r
 \r
                                ADCSRA |= (1 << ADSC);\r
                        }\r
 \r
-                       /** Performs a complete single reading from channel, including a polling spinloop to wait for the\r
+                       /** Performs a complete single reading from channel, including a polling spin-loop to wait for the\r
                         *  conversion to complete, and the returning of the converted value.\r
                         *\r
                         *  conversion to complete, and the returning of the converted value.\r
                         *\r
-                        *  \param[in] MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
+                        *  \param[in] MUXMask  Mask comprising of an ADC channel mask, reference mask and adjustment mask\r
                         */\r
                        static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask) ATTR_WARN_UNUSED_RESULT;\r
                        static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask)\r
                         */\r
                        static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask) ATTR_WARN_UNUSED_RESULT;\r
                        static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask)\r