summaryrefslogtreecommitdiffstats
path: root/nrf24l01/uart.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-02-09 17:55:18 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-02-09 17:55:18 +0800
commit27a890cdf09df58c624047927cb97fbe97728c9c (patch)
treef6b5da78ac54183d3dc726ed6f1adc73fcd0cc48 /nrf24l01/uart.c
parent2d2310b58c34c13212568a2d01c3af7b03c91c48 (diff)
downloadsmart-home-27a890cdf09df58c624047927cb97fbe97728c9c.tar.gz
wip.
Diffstat (limited to 'nrf24l01/uart.c')
-rw-r--r--nrf24l01/uart.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/nrf24l01/uart.c b/nrf24l01/uart.c
new file mode 100644
index 0000000..e5b6e05
--- /dev/null
+++ b/nrf24l01/uart.c
@@ -0,0 +1,33 @@
+#include <avr/io.h>
+#include <util/setbaud.h>
+
+#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);
+}
+
+void uart_write(char c)
+{
+ while (!(UCSR0A & (1 << UDRE0)))
+ ;
+ UDR0 = data;
+}
+
+void uart_write_line(const char *s)
+{
+ for (; *s; s++)
+ serial_write(*s);
+
+ serial_write('\r');
+ serial_write('\n');
+}