summaryrefslogtreecommitdiffstats
path: root/door_lock/uart.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-09-07 17:04:34 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-09-07 17:04:34 +0800
commit276856de6c63bbbf3e56cc08dcca00ba10080b7e (patch)
treec68484bc312cc3a8abcea4fa9f4948a6f1f65cc6 /door_lock/uart.c
parentf4b0b734a595919cf451ab9448b06274c8e609a4 (diff)
downloadsmart-home-276856de6c63bbbf3e56cc08dcca00ba10080b7e.tar.gz
Door lock with MOSFETs and and without RFM.HEADmaster
Diffstat (limited to 'door_lock/uart.c')
-rw-r--r--door_lock/uart.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/door_lock/uart.c b/door_lock/uart.c
new file mode 100644
index 0000000..1a9956d
--- /dev/null
+++ b/door_lock/uart.c
@@ -0,0 +1,31 @@
+#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);
+}
+
+uint8_t uart_recv(void)
+{
+ while (!(UCSR0A & (1 << RXC0)))
+ ;
+ return UDR0;
+}
+
+void uart_send(uint8_t c)
+{
+ while (!(UCSR0A & (1 << UDRE0)))
+ ;
+ UDR0 = c;
+}