#endif\r
\r
/* Public Interface - May be used in end-application: */\r
- /* Macros: */\r
- /** Initializes the ADC, ready for conversions. This must be called before any other ADC operations.\r
- * The "mode" parameter should be a mask comprised of a conversion mode (free running or single) and\r
- * prescaler masks.\r
- */\r
- #define ADC_Init(mode) MACROS{ ADCSRA = ((1 << ADEN) | mode); }MACROE\r
-\r
- /** Turns off the ADC. If this is called, any further ADC operations will require a call to the\r
- * ADC_Init() macro before the ADC can be used again.\r
- */\r
- #define ADC_Off() MACROS{ ADCSRA = 0; }MACROE\r
- \r
- /** Indicates if the ADC is enabled. This macro will return boolean true if the ADC subsystem is\r
- * currently enabled, or false otherwise.\r
- */\r
- #define ADC_GetStatus() ((ADCSRA & (1 << ADEN)) ? true : false)\r
-\r
- /** Indicates if the current ADC conversion is completed, or still in progress. This returns boolean\r
- * false if the reading is still taking place, or true if the conversion is complete and ready to be\r
- * read out with ADC_GetResult().\r
- */\r
- #define ADC_IsReadingComplete() (!(ADCSRA & (1 << ADSC)))\r
- \r
- /** Returns the result of the last conversion, as a 16-bit wide integer. */\r
- #define ADC_GetResult() ADC\r
- \r
+ /* Macros: */ \r
/** Reference mask, for using the voltage present at the AVR's AREF pin for the ADC reference. */\r
#define ADC_REFERENCE_AREF 0\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
+ /* Pseudo-Function Macros: */\r
+ #if defined(__DOXYGEN__)\r
+ /** Initializes the ADC, ready for conversions. This must be called before any other ADC operations.\r
+ * The "mode" parameter should be a mask comprised of a conversion mode (free running or single) and\r
+ * prescaler masks.\r
+ *\r
+ * \param[in] Mode Mask of ADC settings, including adjustment, prescale, mode and reference\r
+ */\r
+ static inline void ADC_Init(uint8_t Mode);\r
+ \r
+ /** Turns off the ADC. If this is called, any further ADC operations will require a call to\r
+ * \ref ADC_Init() before the ADC can be used again.\r
+ */\r
+ static inline void ADC_Off(void);\r
+ \r
+ /** Indicates if the ADC is currently enabled.\r
+ *\r
+ * \return Boolean true if the ADC subsystem is currently enabled, false otherwise.\r
+ */\r
+ static inline bool ADC_GetStatus(void);\r
+ \r
+ /** Indicates if the current ADC conversion is completed, or still in progress.\r
+ *\r
+ * \return Boolean false if the reading is still taking place, or true if the conversion is\r
+ * complete and ready to be read out with \ref ADC_GetResult()\r
+ */\r
+ static inline bool ADC_IsReadingComplete(void);\r
+ \r
+ /** Retrieves the conversion value of the last completed ADC conversion.\r
+ *\r
+ * \return The result of the last ADC conversion\r
+ */\r
+ static inline uint16_t ADC_GetResult(void);\r
+ #else\r
+ #define ADC_Init(mode) MACROS{ ADCSRA = ((1 << ADEN) | mode); }MACROE\r
+\r
+ #define ADC_Off() MACROS{ ADCSRA = 0; }MACROE\r
+ \r
+ #define ADC_GetStatus() ((ADCSRA & (1 << ADEN)) ? true : false)\r
+\r
+ #define ADC_IsReadingComplete() (!(ADCSRA & (1 << ADSC)))\r
+ \r
+ #define ADC_GetResult() ADC \r
+ #endif\r
+ \r
/* Inline Functions: */\r
/** Configures the given ADC channel, ready for ADC conversions. This function sets the\r
* associated port pin as an input and disables the digital portion of the I/O to reduce\r
* power consumption.\r
*\r
- * \param Channel ADC channel number to set up for conversions\r
+ * \param[in] Channel ADC channel number to set up for conversions\r
*/\r
static inline void ADC_SetupChannel(const uint8_t Channel)\r
{\r
+ #if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \\r
+ defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \\r
+ defined(__AVR_ATmega32U6__)) \r
DDRF &= ~(1 << Channel);\r
DIDR0 |= (1 << Channel);\r
+ #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))\r
+ if (Channel < 8)\r
+ {\r
+ DDRF &= ~(1 << Channel);\r
+ DIDR0 |= (1 << Channel);\r
+ }\r
+ else if (Channel == 8)\r
+ {\r
+ DDRD &= ~(1 << 4);\r
+ DIDR2 |= (1 << 0);\r
+ }\r
+ else if (Channel < 11)\r
+ {\r
+ DDRD &= ~(1 << (Channel - 3));\r
+ DIDR2 |= (1 << (Channel - 8));\r
+ }\r
+ else\r
+ {\r
+ DDRB &= ~(1 << (Channel - 7));\r
+ DIDR2 |= (1 << (Channel - 8));\r
+ }\r
+ #endif\r
}\r
\r
/** Starts the reading of the given channel, but does not wait until the conversion has completed.\r
- * Once executed, the conversion status can be determined via the ADC_IsReadingComplete() macro and\r
- * the result read via the ADC_GetResult() macro.\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 MUXMask Mask comprising of an ADC channel number, reference mask and adjustment mask\r
+ * \param[in] MUXMask Mask comprising of an ADC channel number, reference mask and adjustment mask\r
*/\r
static inline void ADC_StartReading(const uint8_t MUXMask)\r
{\r
/** Performs a complete single reading from channel, including a polling spinloop to wait for the\r
* conversion to complete, and the returning of the converted value.\r
*\r
- * \param MUXMask Mask comprising of an ADC channel number, reference mask and adjustment mask\r
+ * \param[in] MUXMask Mask comprising of an ADC channel number, 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