summaryrefslogtreecommitdiffstats
path: root/door_lock/serial.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2024-11-03 14:16:32 +0800
committerSadeep Madurange <sadeep@asciimx.com>2024-11-03 14:16:32 +0800
commit0c1f7fef8447da32a94c7b6784edd9a6b3a12428 (patch)
tree5120196e2748f7fb7d35a0b1178d312fb3accb7b /door_lock/serial.c
parent92807aed3d3dc17fdf94d35d8b26c1d894aab9f2 (diff)
downloadsmart-home-0c1f7fef8447da32a94c7b6784edd9a6b3a12428.tar.gz
Serial console.
Diffstat (limited to 'door_lock/serial.c')
-rw-r--r--door_lock/serial.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/door_lock/serial.c b/door_lock/serial.c
new file mode 100644
index 0000000..4dba0e5
--- /dev/null
+++ b/door_lock/serial.c
@@ -0,0 +1,32 @@
+#include <avr/io.h>
+#include <util/setbaud.h>
+
+#include "serial.h"
+
+void serial_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 void serial_write_raw(unsigned char data)
+{
+ while (!(UCSR0A & (1 << UDRE0)))
+ ;
+ UDR0 = data;
+}
+
+void serial_write(const char *s)
+{
+ for (; *s; s++)
+ serial_write_raw(*s);
+ serial_write_raw('\r');
+ serial_write_raw('\n');
+}