From 2a5eaad1bcac0f0ff61bd82b6427932cb4d03872 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Mon, 7 Apr 2025 12:50:46 +0800 Subject: Copy working NRFM code. --- lock/uart.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lock/uart.c (limited to 'lock/uart.c') diff --git a/lock/uart.c b/lock/uart.c new file mode 100644 index 0000000..a6d6674 --- /dev/null +++ b/lock/uart.c @@ -0,0 +1,37 @@ +#include +#include + +#include "uart.h" + +void uart_init(void) +{ + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; +#if USE_2X + UCSR0A |= (1 << U2X0); +#else + UCSR0A &= ~(1 << U2X0); +#endif + UCSR0B = (1 << TXEN0) | (1 << RXEN0); + UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); +} + +static inline void uart_write_char(char c) +{ + while (!(UCSR0A & (1 << UDRE0))) + ; + UDR0 = c; +} + +void uart_write(const char *s) +{ + for (; *s; s++) + uart_write_char(*s); +} + +void uart_write_line(const char *s) +{ + uart_write(s); + uart_write_char('\r'); + uart_write_char('\n'); +} -- cgit v1.2.3