Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/output/ctl/serial.c

    r28a5ebd rd31c3ea  
    11/*
     2 * Copyright (c) 2024 Jiri Svoboda
    23 * Copyright (c) 2006 Ondrej Palkovsky
    34 * Copyright (c) 2008 Martin Decky
     
    3738#include <errno.h>
    3839#include <io/chargrid.h>
     40#include <vt/vt100.h>
    3941#include "../output.h"
    40 #include "../proto/vt100.h"
    4142#include "serial.h"
    4243
    4344#define SERIAL_COLS  80
    4445#define SERIAL_ROWS  24
     46
     47static serial_putuchar_t serial_putuchar_fn;
     48static serial_control_puts_t serial_control_puts_fn;
     49static serial_flush_t serial_flush_fn;
     50
     51static void serial_vt_putuchar(void *, char32_t);
     52static void serial_vt_control_puts(void *, const char *);
     53static void serial_vt_flush(void *);
     54
     55static vt100_cb_t serial_vt_cb = {
     56        .putuchar = serial_vt_putuchar,
     57        .control_puts = serial_vt_control_puts,
     58        .flush = serial_vt_flush
     59};
    4560
    4661/** Draw the character at the specified position.
     
    5267 *
    5368 */
    54 static void draw_char(vt100_state_t *state, charfield_t *field,
     69static void draw_char(vt100_t *state, charfield_t *field,
    5570    sysarg_t col, sysarg_t row)
    5671{
     
    6277static errno_t serial_yield(outdev_t *dev)
    6378{
    64         vt100_state_t *state = (vt100_state_t *) dev->data;
     79        vt100_t *state = (vt100_t *) dev->data;
    6580
    6681        return vt100_yield(state);
     
    6984static errno_t serial_claim(outdev_t *dev)
    7085{
    71         vt100_state_t *state = (vt100_state_t *) dev->data;
     86        vt100_t *state = (vt100_t *) dev->data;
    7287
    7388        return vt100_claim(state);
     
    7792    sysarg_t *rows)
    7893{
    79         vt100_state_t *state = (vt100_state_t *) dev->data;
     94        vt100_t *state = (vt100_t *) dev->data;
    8095
    8196        vt100_get_dimensions(state, cols, rows);
     
    8499static console_caps_t serial_get_caps(outdev_t *dev)
    85100{
    86         return (CONSOLE_CAP_STYLE | CONSOLE_CAP_INDEXED);
     101        return (CONSOLE_CAP_CURSORCTL | CONSOLE_CAP_STYLE |
     102            CONSOLE_CAP_INDEXED | CONSOLE_CAP_RGB);
    87103}
    88104
     
    90106    sysarg_t prev_row, sysarg_t col, sysarg_t row, bool visible)
    91107{
    92         vt100_state_t *state = (vt100_state_t *) dev->data;
     108        vt100_t *state = (vt100_t *) dev->data;
    93109
    94110        vt100_goto(state, col, row);
     
    98114static void serial_char_update(outdev_t *dev, sysarg_t col, sysarg_t row)
    99115{
    100         vt100_state_t *state = (vt100_state_t *) dev->data;
     116        vt100_t *state = (vt100_t *) dev->data;
    101117        charfield_t *field =
    102118            chargrid_charfield_at(dev->backbuf, col, row);
     
    107123static void serial_flush(outdev_t *dev)
    108124{
    109         vt100_state_t *state = (vt100_state_t *) dev->data;
     125        vt100_t *state = (vt100_t *) dev->data;
    110126
    111127        vt100_flush(state);
     
    122138};
    123139
    124 errno_t serial_init(vt100_putuchar_t putuchar_fn,
    125     vt100_control_puts_t control_puts_fn, vt100_flush_t flush_fn)
     140errno_t serial_init(serial_putuchar_t putuchar_fn,
     141    serial_control_puts_t control_puts_fn, serial_flush_t flush_fn)
    126142{
    127         vt100_state_t *state =
    128             vt100_state_create(SERIAL_COLS, SERIAL_ROWS, putuchar_fn,
    129             control_puts_fn, flush_fn);
    130         if (state == NULL)
     143        char_attrs_t attrs;
     144        vt100_t *vt100;
     145
     146        serial_putuchar_fn = putuchar_fn;
     147        serial_control_puts_fn = control_puts_fn;
     148        serial_flush_fn = flush_fn;
     149
     150        vt100 = vt100_create(NULL, SERIAL_COLS, SERIAL_ROWS, &serial_vt_cb);
     151        if (vt100 == NULL)
    131152                return ENOMEM;
     153        vt100->enable_rgb = true;
    132154
    133         outdev_t *dev = outdev_register(&serial_ops, state);
     155        vt100_cursor_visibility(vt100, false);
     156        attrs.type = CHAR_ATTR_STYLE;
     157        attrs.val.style = STYLE_NORMAL;
     158        vt100_set_attr(vt100, attrs);
     159        vt100_cls(vt100);
     160
     161        outdev_t *dev = outdev_register(&serial_ops, vt100);
    134162        if (dev == NULL) {
    135                 vt100_state_destroy(state);
     163                vt100_destroy(vt100);
    136164                return ENOMEM;
    137165        }
     
    140168}
    141169
     170static void serial_vt_putuchar(void *arg, char32_t c)
     171{
     172        (void)arg;
     173        serial_putuchar_fn(c);
     174}
     175
     176static void serial_vt_control_puts(void *arg, const char *str)
     177{
     178        (void)arg;
     179        serial_control_puts_fn(str);
     180}
     181
     182static void serial_vt_flush(void *arg)
     183{
     184        (void)arg;
     185        serial_flush_fn();
     186}
     187
    142188/** @}
    143189 */
Note: See TracChangeset for help on using the changeset viewer.