Added explicit ADC channel masks for the standard set of ADC channels, as the single...
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 25 Jan 2010 00:52:45 +0000 (00:52 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 25 Jan 2010 00:52:45 +0000 (00:52 +0000)
Demos/Device/ClassDriver/AudioInput/AudioInput.c
Demos/Device/ClassDriver/AudioInput/AudioInput.h
Demos/Device/LowLevel/AudioInput/AudioInput.c
Demos/Device/LowLevel/AudioInput/AudioInput.h
LUFA/Drivers/Board/Temperature.c
LUFA/Drivers/Board/Temperature.h
LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h
LUFA/ManPages/ChangeLog.txt
LUFA/ManPages/MigrationInformation.txt
Projects/AVRISP-MKII/Lib/V2Protocol.c
Projects/AVRISP-MKII/Lib/V2Protocol.h

index eeec921..b90ee51 100644 (file)
@@ -86,7 +86,7 @@ void SetupHardware(void)
        ADC_SetupChannel(MIC_IN_ADC_CHANNEL);\r
        \r
        /* Start the ADC conversion in free running mode */\r
        ADC_SetupChannel(MIC_IN_ADC_CHANNEL);\r
        \r
        /* Start the ADC conversion in free running mode */\r
-       ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_CHANNEL);\r
+       ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_MUX_MASK);\r
 }\r
 \r
 /** Processes the next audio sample by reading the last ADC conversion and writing it to the audio\r
 }\r
 \r
 /** Processes the next audio sample by reading the last ADC conversion and writing it to the audio\r
index ddb6430..98fec78 100644 (file)
@@ -52,6 +52,9 @@
        /* Macros: */\r
                /** ADC channel number for the microphone input. */\r
                #define MIC_IN_ADC_CHANNEL        2\r
        /* Macros: */\r
                /** ADC channel number for the microphone input. */\r
                #define MIC_IN_ADC_CHANNEL        2\r
+               \r
+               /** ADC channel MUX mask for the microphone input. */\r
+               #define MIC_IN_ADC_MUX_MASK       ADC_CHANNEL2\r
 \r
                /** Maximum ADC sample value for the microphone input. */\r
                #define SAMPLE_MAX_RANGE          0xFFFF\r
 \r
                /** Maximum ADC sample value for the microphone input. */\r
                #define SAMPLE_MAX_RANGE          0xFFFF\r
index 98c2e8b..2d718e5 100644 (file)
@@ -72,7 +72,7 @@ void SetupHardware(void)
        USB_Init();\r
        \r
        /* Start the ADC conversion in free running mode */\r
        USB_Init();\r
        \r
        /* Start the ADC conversion in free running mode */\r
-       ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_CHANNEL);\r
+       ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_MUX_MASK);\r
 }\r
 \r
 /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs, and\r
 }\r
 \r
 /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs, and\r
index ace1e96..4585ab5 100644 (file)
@@ -52,6 +52,9 @@
                /** ADC channel number for the microphone input. */\r
                #define MIC_IN_ADC_CHANNEL        2\r
                \r
                /** ADC channel number for the microphone input. */\r
                #define MIC_IN_ADC_CHANNEL        2\r
                \r
+               /** ADC channel MUX mask for the microphone input. */\r
+               #define MIC_IN_ADC_MUX_MASK       ADC_CHANNEL2\r
+               \r
                /** Maximum ADC sample value for the microphone input. */\r
                #define SAMPLE_MAX_RANGE          0xFFFF\r
 \r
                /** Maximum ADC sample value for the microphone input. */\r
                #define SAMPLE_MAX_RANGE          0xFFFF\r
 \r
index 748e048..ea12bf7 100644 (file)
@@ -45,7 +45,7 @@ static const uint16_t PROGMEM Temperature_Lookup[] = {
 \r
 int8_t Temperature_GetTemperature(void)\r
 {\r
 \r
 int8_t Temperature_GetTemperature(void)\r
 {\r
-       uint16_t Temp_ADC = ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | TEMP_ADC_CHANNEL);\r
+       uint16_t Temp_ADC = ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | TEMP_ADC_CHANNEL_MASK);\r
 \r
        if (Temp_ADC > pgm_read_word(&Temperature_Lookup[0]))\r
          return TEMP_MIN_TEMP;\r
 \r
        if (Temp_ADC > pgm_read_word(&Temperature_Lookup[0]))\r
          return TEMP_MIN_TEMP;\r
index f7f0034..1b2baf2 100644 (file)
        /* Public Interface - May be used in end-application: */\r
                /* Macros: */\r
                        /** ADC channel number for the temperature sensor. */\r
        /* Public Interface - May be used in end-application: */\r
                /* Macros: */\r
                        /** ADC channel number for the temperature sensor. */\r
-                       #define TEMP_ADC_CHANNEL   0\r
+                       #define TEMP_ADC_CHANNEL       0\r
                        \r
                        \r
+                       /** ADC channel MUX mask for the temperature sensor. */\r
+                       #define TEMP_ADC_CHANNEL_MASK  ADC_CHANNEL0\r
+\r
                        /** Minimum returnable temperature from the \ref Temperature_GetTemperature() function. */\r
                        /** Minimum returnable temperature from the \ref Temperature_GetTemperature() function. */\r
-                       #define TEMP_MIN_TEMP      TEMP_TABLE_OFFSET\r
+                       #define TEMP_MIN_TEMP          TEMP_TABLE_OFFSET\r
 \r
                        /** Maximum returnable temperature from the \ref Temperature_GetTemperature() function. */\r
 \r
                        /** Maximum returnable temperature from the \ref Temperature_GetTemperature() function. */\r
-                       #define TEMP_MAX_TEMP      ((TEMP_TABLE_SIZE - 1) + TEMP_TABLE_OFFSET)\r
+                       #define TEMP_MAX_TEMP          ((TEMP_TABLE_SIZE - 1) + TEMP_TABLE_OFFSET)\r
                \r
                /* Pseudo-Function Macros: */\r
                        #if defined(__DOXYGEN__)\r
                \r
                /* Pseudo-Function Macros: */\r
                        #if defined(__DOXYGEN__)\r
index 472e1df..b0a9b9e 100644 (file)
 \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
+                       /** MUX mask define for the ADC2 channel of the ADC. See \ref ADC_StartReading and \ref ADC_GetChannelReading. */\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
+                       #define  ADC_CHANNEL3                    0x03\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
 \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
                         *  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
                        /** 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
                        /** 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
-                        *  \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
index e5bdbb3..8a46a5a 100644 (file)
@@ -18,6 +18,8 @@
   *    sent or received in packed form in a single USB packet\r
   *  - Added new MIDI send buffer flush routines to the MIDI Device and Host mode Class drivers, to flush packed events\r
   *  - Added master mode hardware TWI driver\r
   *    sent or received in packed form in a single USB packet\r
   *  - Added new MIDI send buffer flush routines to the MIDI Device and Host mode Class drivers, to flush packed events\r
   *  - Added master mode hardware TWI driver\r
+  *  - Added ADC MUX masks for the standard ADC input channels on all AVR models with an ADC, altered demos to use these masks\r
+  *    as on some models, the channel number is not identical to its single-ended ADC MUX mask\r
   *\r
   *  <b>Changed:</b>\r
   *  - Slowed down software USART carried PDI programming in the AVRISP project to prevent transmission errors\r
   *\r
   *  <b>Changed:</b>\r
   *  - Slowed down software USART carried PDI programming in the AVRISP project to prevent transmission errors\r
index cf81901..9f21118 100644 (file)
  *\r
  * \section Sec_MigrationXXXXXX Migrating from 091223 to XXXXXX\r
  *\r
  *\r
  * \section Sec_MigrationXXXXXX Migrating from 091223 to XXXXXX\r
  *\r
+ *  <b>Non-USB Library Components</b>\r
+ *    - Due to some ADC channels not being identical to their ADC MUX selection masks for single-ended conversions on some AVR models,\r
+ *      the ADC driver now has explicit masks for each of the standard ADC channels. These masks should be used when calling the ADC\r
+ *      functions to ensure proper operation across all AVR models. Note that the \ref ADC_SetupChannel() function is an exception, and\r
+ *      should always be called with a channel number rather than a channel mask.\r
+ *\r
  *  <b>Host Mode</b>\r
  *    - The MIDI Host Class driver send and receive routines now operate on packed events, where multiple MIDI events may be\r
  *      packed into a single USB packet. This means that the sending of MIDI events will now be delayed until the MIDI send\r
  *  <b>Host Mode</b>\r
  *    - The MIDI Host Class driver send and receive routines now operate on packed events, where multiple MIDI events may be\r
  *      packed into a single USB packet. This means that the sending of MIDI events will now be delayed until the MIDI send\r
index d6de774..8d8f200 100644 (file)
@@ -57,7 +57,7 @@ void V2Protocol_Init(void)
        /* Initialize the ADC converter for VTARGET level detection on supported AVR models */\r
        ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);\r
        ADC_SetupChannel(VTARGET_ADC_CHANNEL);\r
        /* Initialize the ADC converter for VTARGET level detection on supported AVR models */\r
        ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);\r
        ADC_SetupChannel(VTARGET_ADC_CHANNEL);\r
-       ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);\r
+       ADC_StartReading(VTARGET_ADC_CHANNEL_MASK | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);\r
        #endif\r
        \r
        /* Millisecond timer initialization for managing the command timeout counter */\r
        #endif\r
        \r
        /* Millisecond timer initialization for managing the command timeout counter */\r
index 862ea48..5af9fe9 100644 (file)
                #endif\r
 \r
        /* Macros: */\r
                #endif\r
 \r
        /* Macros: */\r
+               #if !defined(__DOXYGEN__)\r
+                       #define _GETADCMUXMASK2(x, y)       x ## y\r
+                       #define _GETADCMUXMASK(x, y)        _GETADCMUXMASK2(x, y)\r
+               #endif\r
+\r
                /** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */\r
                /** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */\r
-               #define PROGRAMMER_ID       "AVRISP_MK2"\r
+               #define PROGRAMMER_ID              "AVRISP_MK2"\r
                \r
                /** Timeout period for each issued command from the host before it is aborted */\r
                \r
                /** Timeout period for each issued command from the host before it is aborted */\r
-               #define COMMAND_TIMEOUT_MS   200\r
+               #define COMMAND_TIMEOUT_MS         200\r
                \r
                /** Command timeout counter register, GPIOR for speed */\r
                \r
                /** Command timeout counter register, GPIOR for speed */\r
-               #define TimeoutMSRemaining   GPIOR0\r
+               #define TimeoutMSRemaining         GPIOR0\r
+               \r
+               /** MUX mask for the VTARGET ADC channel number */\r
+               #define VTARGET_ADC_CHANNEL_MASK   _GETADCMUXMASK(ADC_CHANNEL, VTARGET_ADC_CHANNEL)\r
 \r
        /* External Variables: */\r
                extern uint32_t CurrentAddress;\r
 \r
        /* External Variables: */\r
                extern uint32_t CurrentAddress;\r