summaryrefslogtreecommitdiffstats
path: root/batchk/uart.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-05-01 11:05:40 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-05-01 11:05:40 +0800
commit57e9d1a5c00dc7dc5cf3149c35a8004b5f7aab7f (patch)
tree7d45b11513f09f9f4bfb488d167a5dd30691e4a1 /batchk/uart.c
parentd11b0f733b293c768f1bca6bc54ae88997d691a2 (diff)
downloadsmart-home-57e9d1a5c00dc7dc5cf3149c35a8004b5f7aab7f.tar.gz
Measure vcc.
Diffstat (limited to 'batchk/uart.c')
-rw-r--r--batchk/uart.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/batchk/uart.c b/batchk/uart.c
new file mode 100644
index 0000000..a6d6674
--- /dev/null
+++ b/batchk/uart.c
@@ -0,0 +1,37 @@
+#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);
+}
+
+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');
+}