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