MOS Source Code
Loading...
Searching...
No Matches
serial_console.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
4
5#include "ansi_colors.h"
7
9#include <mos_stdio.hpp>
10#include <mos_string.hpp>
11
12bool serial_console_irq_handler(u32 irq, void *data)
13{
14 MOS_UNUSED(irq);
15
16 Console *const console = (Console *) data;
17 SerialConsole *const serial_con = static_cast<SerialConsole *>(console);
18 serial_con->handle_irq();
19
20 return true;
21}
22
23size_t SerialConsole::do_write(const char *data, size_t size)
24{
25 return device->write_data(data, size);
26}
27
29{
30 if (this->fg == fg && this->bg == bg)
31 return true; // no change
32
33 this->fg = fg;
34 this->bg = bg;
35 char buf[64] = { 0 };
36 get_ansi_color(buf, fg, bg);
37 device->write_data(ANSI_COLOR_RESET, sizeof(ANSI_COLOR_RESET) - 1);
38 device->write_data(buf, strlen(buf));
39 return true;
40}
41
43{
44 device->write_data("\033[2J", 4);
45 return true;
46}
47
49{
50 while (device->get_data_ready())
51 {
52 char c = device->ReadByte();
53 if (c == '\r')
54 c = '\n';
55 if (c == '\0')
56 break;
57 device->WriteByte(c);
58 this->putc(c);
59 }
60};
bool set_color(StandardColor fg, StandardColor bg) override
ISerialDevice * device
size_t do_write(const char *data, size_t size) override
bool clear() override
should_inline void get_ansi_color(char *buf, StandardColor fg, StandardColor bg)
Definition ansi_colors.h:80
#define ANSI_COLOR_RESET
Definition ansi_colors.h:49
StandardColor
Definition ansi_colors.h:18
#define MOS_UNUSED(x)
Definition mos_global.h:65
static size_t strlen(const char *s)
Definition pb_syshdr.h:80
bool serial_console_irq_handler(u32 irq, void *data)
size_t size
Definition slab.cpp:32
StandardColor bg
Definition console.hpp:36
void putc(u8 c)
Definition console.cpp:125
StandardColor fg
Definition console.hpp:36
unsigned int u32
Definition types.h:17