diff options
-rw-r--r-- | LUFA/ChangeLog.txt | 2 | ||||
-rw-r--r-- | LUFA/Drivers/Peripheral/Serial.c | 12 | ||||
-rw-r--r-- | LUFA/Drivers/Peripheral/Serial.h | 27 |
3 files changed, 21 insertions, 20 deletions
diff --git a/LUFA/ChangeLog.txt b/LUFA/ChangeLog.txt index 98b82d35a..bca8d9fb9 100644 --- a/LUFA/ChangeLog.txt +++ b/LUFA/ChangeLog.txt @@ -78,6 +78,8 @@ * - Changed LED board driver code to define dummy LED masks for the first four board LEDs, so that user code can be compiled for boards
* with less than four LEDs without code modifications (thanks to Morten Lund)
* - Changed HWB board driver to Buttons driver, to allow for the support of future boards with more than one mounted GPIO button
+ * - Serial driver now correctly calculates the baud register value when in double speed mode
+ * - Init function of the Serial driver is now static inline to product smaller code for the common-case of static init values
*
*
* \section Sec_ChangeLog090401 Version 090401
diff --git a/LUFA/Drivers/Peripheral/Serial.c b/LUFA/Drivers/Peripheral/Serial.c index e1c744922..f9aa6a732 100644 --- a/LUFA/Drivers/Peripheral/Serial.c +++ b/LUFA/Drivers/Peripheral/Serial.c @@ -30,18 +30,6 @@ #include "Serial.h"
-void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed)
-{
- UCSR1A = ((DoubleSpeed) ? (1 << U2X1) : 0);
- UCSR1B = ((1 << RXEN1) | (1 << TXEN1));
- UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10));
-
- DDRD |= (1 << 3);
- PORTD |= (1 << 2);
-
- UBRR1 = SERIAL_UBBRVAL(BaudRate);
-}
-
void Serial_TxString_P(const char *FlashStringPtr)
{
uint8_t CurrByte;
diff --git a/LUFA/Drivers/Peripheral/Serial.h b/LUFA/Drivers/Peripheral/Serial.h index a50456b37..7e718fe0c 100644 --- a/LUFA/Drivers/Peripheral/Serial.h +++ b/LUFA/Drivers/Peripheral/Serial.h @@ -63,7 +63,7 @@ #endif
/* Public Interface - May be used in end-application: */
- /* Macros: */
+ /* Macros: */
/** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is
* not set.
*/
@@ -86,13 +86,6 @@ #endif
/* Function Prototypes: */
- /** Initializes the USART, ready for serial data transmission and reception.
- *
- * \param BaudRate Baud rate to configure the USART to
- * \param DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate
- */
- void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed);
-
/** Transmits a given string located in program space (FLASH) through the USART.
*
* \param FlashStringPtr Pointer to a string located in program space
@@ -106,6 +99,24 @@ void Serial_TxString(const char *StringPtr) ATTR_NON_NULL_PTR_ARG(1);
/* Inline Functions: */
+ /** Initializes the USART, ready for serial data transmission and reception. This initialises the interface to
+ * standard 8-bit, no parity, 1 stop bit settings suitable for most applications.
+ *
+ * \param BaudRate Serial baud rate, in bits per second
+ * \param DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate
+ */
+ static inline void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed)
+ {
+ UCSR1A = (DoubleSpeed ? (1 << U2X1) : 0);
+ UCSR1B = ((1 << TXEN1) | (1 << RXEN1));
+ UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10));
+
+ DDRD |= (1 << 3);
+ PORTD |= (1 << 2);
+
+ UBRR1 = (DoubleSpeed ? SERIAL_2X_UBBRVAL(BaudRate) : SERIAL_UBBRVAL(BaudRate));
+ }
+
/** Transmits a given byte through the USART.
*
* \param DataByte Byte to transmit through the USART
|