MOS Source Code
Loading...
Searching...
No Matches
serial_console.c
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_string.h>
10
11static size_t serial_console_write(console_t *console, const char *str, size_t len)
12{
13 serial_console_t *serial_con = container_of(console, serial_console_t, con);
14 return serial_device_write(&serial_con->device, str, len);
15}
16
18{
19 serial_console_t *serial_con = container_of(console, serial_console_t, con);
20 serial_con->fg = fg;
21 serial_con->bg = bg;
22 char buf[64] = { 0 };
23 get_ansi_color(buf, fg, bg);
25 serial_device_write(&serial_con->device, buf, strlen(buf));
26 return true;
27}
28
30{
31 serial_console_t *serial_con = container_of(console, serial_console_t, con);
32 *fg = serial_con->fg;
33 *bg = serial_con->bg;
34 return true;
35}
36
37static bool serial_console_clear(console_t *console)
38{
39 serial_console_t *serial_con = container_of(console, serial_console_t, con);
40 serial_device_write(&serial_con->device, "\033[2J", 4);
41 return true;
42}
43
45{
47
48 serial_console_t *const serial_con = container_of(console, serial_console_t, con);
49
50 if (!console->ops->write)
51 console->ops->write = serial_console_write;
52
53 console->caps |= CONSOLE_CAP_COLOR;
54 if (!console->ops->set_color)
55 console->ops->set_color = serial_console_set_color;
56
57 if (!console->ops->get_color)
58 console->ops->get_color = serial_console_get_color;
59
60 console->caps |= CONSOLE_CAP_CLEAR;
61 if (!console->ops->clear)
62 console->ops->clear = serial_console_clear;
63
64 return serial_device_setup(&serial_con->device);
65}
66
67bool serial_console_irq_handler(u32 irq, void *data)
68{
69 MOS_UNUSED(irq);
70
71 console_t *const console = (console_t *) data;
72 serial_console_t *const serial_con = container_of(console, serial_console_t, con);
73
74 while (serial_dev_get_data_ready(&serial_con->device))
75 {
76 char c = '\0';
77 serial_device_read(&serial_con->device, &c, 1);
78 if (c == '\r')
79 c = '\n';
80 serial_device_write(&serial_con->device, &c, 1);
81 console_putc(&serial_con->con, c);
82 }
83
84 return true;
85}
void console_putc(console_t *con, u8 c)
Definition console.c:148
@ CONSOLE_CAP_COLOR
Definition console.h:15
@ CONSOLE_CAP_CLEAR
Definition console.h:16
should_inline void get_ansi_color(char *buf, standard_color_t fg, standard_color_t bg)
Definition ansi_colors.h:80
#define ANSI_COLOR_RESET
Definition ansi_colors.h:49
standard_color_t
Definition ansi_colors.h:18
MOSAPI void linked_list_init(list_node_t *head_node)
Initialise a circular double linked list.
Definition list.c:15
#define list_node(element)
Get the ‘list_node’ of a list element. This is exactly the reverse of ‘list_entry’ above.
Definition list.h:68
#define MOS_UNUSED(x)
Definition mos_global.h:64
#define container_of(ptr, type, member)
Definition mos_global.h:50
static size_t strlen(const char *s)
Definition pb_syshdr.h:80
int serial_device_read(serial_device_t *device, char *data, size_t length)
Definition serial.c:169
bool serial_dev_get_data_ready(serial_device_t *device)
Definition serial.c:141
bool serial_device_setup(serial_device_t *device)
Definition serial.c:112
int serial_device_write(serial_device_t *device, const char *data, size_t length)
Definition serial.c:158
static bool serial_console_clear(console_t *console)
static size_t serial_console_write(console_t *console, const char *str, size_t len)
static bool serial_console_get_color(console_t *console, standard_color_t *fg, standard_color_t *bg)
static bool serial_console_set_color(console_t *console, standard_color_t fg, standard_color_t bg)
bool serial_console_setup(console_t *console)
bool serial_console_irq_handler(u32 irq, void *data)
console_caps caps
Definition console.h:32
struct console_ops * ops
Definition console.h:30
standard_color_t fg
standard_color_t bg
serial_device_t device
unsigned int u32
Definition types.h:21