aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/Peripheral
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-07-22 15:38:12 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-07-22 15:38:12 +0000
commit9b0e4b8356eb79003a806d010f4b00123350ed90 (patch)
treebf3c74f3cf45da2990995252dd74226fe793d755 /LUFA/Drivers/Peripheral
parent2461ae508c32914ff8aa0920ed99d4fceb18b141 (diff)
downloadlufa-9b0e4b8356eb79003a806d010f4b00123350ed90.tar.gz
lufa-9b0e4b8356eb79003a806d010f4b00123350ed90.tar.bz2
lufa-9b0e4b8356eb79003a806d010f4b00123350ed90.zip
Convert over internal pseudo-function macros to true inline functions for added type-safety and compile-checking.
Diffstat (limited to 'LUFA/Drivers/Peripheral')
-rw-r--r--LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h100
-rw-r--r--LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h35
-rw-r--r--LUFA/Drivers/Peripheral/Serial.h23
3 files changed, 85 insertions, 73 deletions
diff --git a/LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h b/LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h
index 756ec649d..835fee47e 100644
--- a/LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h
+++ b/LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h
@@ -196,52 +196,6 @@
#define ADC_INT_TEMP_SENS ((1 << 8) | (0x07 << MUX0))
#endif
//@}
-
- /* 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_ShutDown(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 and clears the reading
- * completion flag.
- *
- * \return The result of the last ADC conversion as an unsigned value.
- */
- static inline uint16_t ADC_GetResult(void);
- #else
- #define ADC_Init(mode) MACROS{ ADCSRA = ((1 << ADEN) | mode); }MACROE
-
- #define ADC_ShutDown() MACROS{ ADCSRA = 0; }MACROE
-
- #define ADC_GetStatus() ((ADCSRA & (1 << ADEN)) ? true : false)
-
- #define ADC_IsReadingComplete() ((ADCSRA & (1 << ADIF)) ? true : false)
-
- #define ADC_GetResult() (ADCSRA |= (1 << ADIF), ADC)
- #endif
/* Inline Functions: */
/** Configures the given ADC channel, ready for ADC conversions. This function sets the
@@ -354,6 +308,29 @@
ADCSRA |= (1 << ADSC);
}
+ /** 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) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool ADC_IsReadingComplete(void)
+ {
+ return ((ADCSRA & (1 << ADIF)) ? true : false);
+ }
+
+ /** Retrieves the conversion value of the last completed ADC conversion and clears the reading
+ * completion flag.
+ *
+ * \return The result of the last ADC conversion as an unsigned value.
+ */
+ static inline uint16_t ADC_GetResult(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t ADC_GetResult(void)
+ {
+ ADCSRA |= (1 << ADIF);
+ return ADC;
+ }
+
/** Performs a complete single reading from channel, including a polling spin-loop to wait for the
* conversion to complete, and the returning of the converted value.
*
@@ -373,6 +350,37 @@
return ADC_GetResult();
}
+ /** 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) ATTR_ALWAYS_INLINE;
+ static inline void ADC_Init(uint8_t Mode)
+ {
+ ADCSRA = ((1 << ADEN) | 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_ShutDown(void) ATTR_ALWAYS_INLINE;
+ static inline void ADC_ShutDown(void)
+ {
+ ADCSRA = 0;
+ }
+
+ /** 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) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool ADC_GetStatus(void)
+ {
+ return ((ADCSRA & (1 << ADEN)) ? true : false);
+ }
+
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
diff --git a/LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h b/LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h
index 8b289fb66..e2c3d6a10 100644
--- a/LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h
+++ b/LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h
@@ -70,24 +70,27 @@
#endif
/* Public Interface - May be used in end-application: */
- /* Pseudo-Function Macros: */
- #if defined(__DOXYGEN__)
- /** Initializes the TWI hardware into master mode, ready for data transmission and reception. This must be
- * before any other TWI operations.
- */
- static inline void TWI_Init(void);
-
- /** Turns off the TWI driver hardware. If this is called, any further TWI operations will require a call to
- * \ref TWI_Init() before the TWI can be used again.
- */
- static inline void TWI_ShutDown(void);
- #else
- #define TWI_Init() MACROS{ TWCR |= (1 << TWEN); }MACROE
- #define TWI_ShutDown() MACROS{ TWCR &= ~(1 << TWEN); }MACROE
- #endif
-
/* Inline Functions: */
+ /** Initializes the TWI hardware into master mode, ready for data transmission and reception. This must be
+ * before any other TWI operations.
+ */
+ static inline void TWI_Init(void) ATTR_ALWAYS_INLINE;
+ static inline void TWI_Init(void)
+ {
+ TWCR |= (1 << TWEN);
+ }
+
+ /** Turns off the TWI driver hardware. If this is called, any further TWI operations will require a call to
+ * \ref TWI_Init() before the TWI can be used again.
+ */
+ static inline void TWI_ShutDown(void) ATTR_ALWAYS_INLINE;
+ static inline void TWI_ShutDown(void)
+ {
+ TWCR &= ~(1 << TWEN);
+ }
+
/** Sends a TWI STOP onto the TWI bus, terminating communication with the currently addressed device. */
+ static inline void TWI_StopTransmission(void) ATTR_ALWAYS_INLINE;
static inline void TWI_StopTransmission(void)
{
TWCR = ((1 << TWINT) | (1 << TWSTO) | (1 << TWEN));
diff --git a/LUFA/Drivers/Peripheral/Serial.h b/LUFA/Drivers/Peripheral/Serial.h
index 83bdbbf00..4eb74b9d2 100644
--- a/LUFA/Drivers/Peripheral/Serial.h
+++ b/LUFA/Drivers/Peripheral/Serial.h
@@ -76,17 +76,6 @@
*/
#define SERIAL_2X_UBBRVAL(baud) ((((F_CPU / 8) + (baud / 2)) / (baud)) - 1)
- /* Pseudo-Function Macros: */
- #if defined(__DOXYGEN__)
- /** Indicates whether a character has been received through the USART.
- *
- * \return Boolean true if a character has been received, false otherwise.
- */
- static inline bool Serial_IsCharReceived(void);
- #else
- #define Serial_IsCharReceived() ((UCSR1A & (1 << RXC1)) ? true : false)
- #endif
-
/* Function Prototypes: */
/** Transmits a given string located in program space (FLASH) through the USART.
*
@@ -132,11 +121,22 @@
UBRR1 = 0;
}
+
+ /** Indicates whether a character has been received through the USART.
+ *
+ * \return Boolean true if a character has been received, false otherwise.
+ */
+ static inline bool Serial_IsCharReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Serial_IsCharReceived(void)
+ {
+ return ((UCSR1A & (1 << RXC1)) ? true : false);
+ }
/** Transmits a given byte through the USART.
*
* \param[in] DataByte Byte to transmit through the USART.
*/
+ static inline void Serial_TxByte(const char DataByte) ATTR_ALWAYS_INLINE;
static inline void Serial_TxByte(const char DataByte)
{
while (!(UCSR1A & (1 << UDRE1)));
@@ -147,6 +147,7 @@
*
* \return Byte received from the USART.
*/
+ static inline char Serial_RxByte(void) ATTR_ALWAYS_INLINE;
static inline char Serial_RxByte(void)
{
while (!(UCSR1A & (1 << RXC1)));