diff options
Diffstat (limited to 'tmk_core/protocol/serial_uart.c')
-rw-r--r-- | tmk_core/protocol/serial_uart.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tmk_core/protocol/serial_uart.c b/tmk_core/protocol/serial_uart.c index a15124193..4fe059e7d 100644 --- a/tmk_core/protocol/serial_uart.c +++ b/tmk_core/protocol/serial_uart.c | |||
@@ -40,6 +40,22 @@ POSSIBILITY OF SUCH DAMAGE. | |||
40 | #include <avr/interrupt.h> | 40 | #include <avr/interrupt.h> |
41 | #include "serial.h" | 41 | #include "serial.h" |
42 | 42 | ||
43 | #ifndef SERIAL_UART_BAUD | ||
44 | # define SERIAL_UART_BAUD 9600 | ||
45 | #endif | ||
46 | |||
47 | #define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1) | ||
48 | #define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1)) | ||
49 | #define SERIAL_UART_RXD_VECT USART1_RX_vect | ||
50 | |||
51 | #ifndef SERIAL_UART_INIT_CUSTOM | ||
52 | # define SERIAL_UART_INIT_CUSTOM \ | ||
53 | /* enable TX */ \ | ||
54 | UCSR1B = _BV(TXEN1); \ | ||
55 | /* 8-bit data */ \ | ||
56 | UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); | ||
57 | #endif | ||
58 | |||
43 | #if defined(SERIAL_UART_RTS_LO) && defined(SERIAL_UART_RTS_HI) | 59 | #if defined(SERIAL_UART_RTS_LO) && defined(SERIAL_UART_RTS_HI) |
44 | // Buffer state | 60 | // Buffer state |
45 | // Empty: RBUF_SPACE == RBUF_SIZE(head==tail) | 61 | // Empty: RBUF_SPACE == RBUF_SIZE(head==tail) |
@@ -61,7 +77,14 @@ POSSIBILITY OF SUCH DAMAGE. | |||
61 | # define rbuf_check_rts_hi() | 77 | # define rbuf_check_rts_hi() |
62 | #endif | 78 | #endif |
63 | 79 | ||
64 | void serial_init(void) { SERIAL_UART_INIT(); } | 80 | void serial_init(void) { |
81 | do { | ||
82 | // Set baud rate | ||
83 | UBRR1L = SERIAL_UART_UBRR; | ||
84 | UBRR1L = SERIAL_UART_UBRR >> 8; | ||
85 | SERIAL_UART_INIT_CUSTOM; | ||
86 | } while (0); | ||
87 | } | ||
65 | 88 | ||
66 | // RX ring buffer | 89 | // RX ring buffer |
67 | #define RBUF_SIZE 256 | 90 | #define RBUF_SIZE 256 |