aboutsummaryrefslogtreecommitdiff
path: root/drivers/serial.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/serial.h')
-rw-r--r--drivers/serial.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/serial.h b/drivers/serial.h
new file mode 100644
index 0000000..0579dd4
--- /dev/null
+++ b/drivers/serial.h
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <stdlib.h>
+#include "ports.h"
+
+/*
+ * Serial Port
+ *
+ * useful links:
+ * https://wiki.osdev.org/Serial_Ports
+ * https://www.lowlevel.eu/wiki/Serielle_Schnittstelle
+ */
+
+class SerialPort : public Console {
+public:
+ SerialPort();
+ ~SerialPort() = default;
+
+ bool ready_read();
+ uint8_t read();
+
+ bool ready_write();
+ void write(char c) override;
+ void write(ViewIterator& iter) override {
+ while (iter) {
+ write(iter.next());
+ }
+ }
+
+ void update_cursor() override {}
+
+private:
+ enum PortOffset : uint16_t {
+ BaudDiv_l = 0, // if dlab is set
+ BaudDiv_h = 1, // if dlab is set
+ Data = 0, // read from receive buffer / write to transmit buffer
+ InterruptControl = 1, // interrupt enable
+ FifoControl = 2, // interrupt ID and FIFO control
+ LineControl = 3, // most significant bit is the DLAB
+ ModemControl = 4,
+ LineStatus = 5,
+ ModemStatus = 6,
+ Scratch = 7,
+ };
+
+ com1_port_t port;
+};