summaryrefslogtreecommitdiff
path: root/usart.h
diff options
context:
space:
mode:
Diffstat (limited to 'usart.h')
-rw-r--r--usart.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/usart.h b/usart.h
new file mode 100644
index 0000000..6c145c6
--- /dev/null
+++ b/usart.h
@@ -0,0 +1,24 @@
+#ifndef USART_H
+#define USART_H
+
+template<>
+void interrupt<Interrupt::USART1>() {
+ USART1.DR;
+ GPIOA.ODR ^= 1 << 5;
+}
+
+void usart_enable() {
+ RCC.enable(RCC.USART1);
+ USART1.BRR = 7500; // 9600 baud
+ USART1.CR1 = 0x202c;
+
+ Interrupt::enable(Interrupt::USART1);
+}
+
+void usart_send(uint8_t data) {
+ while(!(USART1.SR & 0x80)); // Wait for TXE.
+
+ USART1.DR = data;
+}
+
+#endif