summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--digital/avr/modules/uart/uart.avr.c11
-rw-r--r--digital/avr/modules/uart/uart.h8
-rw-r--r--digital/avr/modules/uart/uart.txt3
-rw-r--r--digital/avr/modules/uart/uart_common.h1
4 files changed, 21 insertions, 2 deletions
diff --git a/digital/avr/modules/uart/uart.avr.c b/digital/avr/modules/uart/uart.avr.c
index ff735213..c28f2f22 100644
--- a/digital/avr/modules/uart/uart.avr.c
+++ b/digital/avr/modules/uart/uart.avr.c
@@ -245,9 +245,7 @@ void
uart_init (void)
{
/* Set baud rate. */
-#if (UBRR_VAL >> 8) != 0
UBRRH = UBRR_VAL >> 8;
-#endif
UBRRL = UBRR_VAL & 0xff;
UCSRA = 0;
/* Set format and enable uart. */
@@ -263,6 +261,15 @@ uart_init (void)
#endif
}
+/** Change uart speed after init. */
+void
+uart_set_speed (uint32_t speed)
+{
+ uint16_t ubrr_val = AC_FREQ / 16 / speed - 1;
+ UBRRH = ubrr_val >> 8;
+ UBRRL = ubrr_val & 0xff;
+}
+
/** Read a char. */
uint8_t
uart_getc (void)
diff --git a/digital/avr/modules/uart/uart.h b/digital/avr/modules/uart/uart.h
index f4d5c525..7cc93a7c 100644
--- a/digital/avr/modules/uart/uart.h
+++ b/digital/avr/modules/uart/uart.h
@@ -29,6 +29,10 @@
void
uart0_init (void);
+/** Change uart speed after init. */
+void
+uart0_set_speed (uint32_t speed);
+
/** Read a char. */
uint8_t
uart0_getc (void);
@@ -45,6 +49,10 @@ uart0_poll (void);
void
uart1_init (void);
+/** Change uart speed after init. */
+void
+uart1_set_speed (uint32_t speed);
+
/** Read a char. */
uint8_t
uart1_getc (void);
diff --git a/digital/avr/modules/uart/uart.txt b/digital/avr/modules/uart/uart.txt
index 30116732..966ae29c 100644
--- a/digital/avr/modules/uart/uart.txt
+++ b/digital/avr/modules/uart/uart.txt
@@ -40,6 +40,9 @@ Only one port can be configured to be used in the STDIO mode. In this mode,
there is an automatic conversion between carriage returns and line feeds (this
is also not good if you plan to use it for binary transfers.
+On AVR, there is also a ``uartN_set_speed`` to change speed after the UART was
+initialized.
+
API
===
diff --git a/digital/avr/modules/uart/uart_common.h b/digital/avr/modules/uart/uart_common.h
index 4704f59c..ffd49f19 100644
--- a/digital/avr/modules/uart/uart_common.h
+++ b/digital/avr/modules/uart/uart_common.h
@@ -40,6 +40,7 @@
#define uart_error_code uart (error_code)
#define uart_getc uart (getc)
#define uart_init uart (init)
+#define uart_set_speed uart (set_speed)
#define uart_poll uart (poll)
#define uart_putc uart (putc)
#define uart_recv_buffer uart (recv_buffer)