aboutsummaryrefslogtreecommitdiff
path: root/drivers/serial.h
blob: 896d831ae128fd464757a7d17e234178572534a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#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 self_check() const { return self_check_okay; }

  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:
  bool self_check_okay;

  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;
};