source: mainline/uspace/srv/hid/output/ctl/serial.c@ b266f9e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b266f9e was 6d5e378, checked in by Martin Decky <martin@…>, 13 years ago

cherrypick GUI implementation (originally by Petr Koupy), with several major changes

  • for character-oriented devices a new output server and output protocol was created based on the original fb server
  • DDF visualizer drivers are pixel-oriented only
  • console and compositor can coexist in the same build
  • terminal widget is self-sufficient, no strange console nesting is needed
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * Copyright (c) 2008 Martin Decky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup console
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <sys/types.h>
38#include <errno.h>
39#include <io/chargrid.h>
40#include "../output.h"
41#include "../proto/vt100.h"
42#include "serial.h"
43
44#define SERIAL_COLS 80
45#define SERIAL_ROWS 24
46
47/** Draw the character at the specified position.
48 *
49 * @param state VT100 protocol state.
50 * @param field Character field.
51 * @param col Horizontal screen position.
52 * @param row Vertical screen position.
53 *
54 */
55static void draw_char(vt100_state_t *state, charfield_t *field,
56 sysarg_t col, sysarg_t row)
57{
58 vt100_goto(state, col, row);
59 vt100_set_attr(state, field->attrs);
60 vt100_putchar(state, field->ch);
61}
62
63static int serial_yield(outdev_t *dev)
64{
65 vt100_state_t *state = (vt100_state_t *) dev->data;
66
67 return vt100_yield(state);
68}
69
70static int serial_claim(outdev_t *dev)
71{
72 vt100_state_t *state = (vt100_state_t *) dev->data;
73
74 return vt100_claim(state);
75}
76
77static void serial_get_dimensions(outdev_t *dev, sysarg_t *cols,
78 sysarg_t *rows)
79{
80 vt100_state_t *state = (vt100_state_t *) dev->data;
81
82 vt100_get_dimensions(state, cols, rows);
83}
84
85static console_caps_t serial_get_caps(outdev_t *dev)
86{
87 return (CONSOLE_CAP_STYLE | CONSOLE_CAP_INDEXED);
88}
89
90static void serial_cursor_update(outdev_t *dev, sysarg_t prev_col,
91 sysarg_t prev_row, sysarg_t col, sysarg_t row, bool visible)
92{
93 vt100_state_t *state = (vt100_state_t *) dev->data;
94
95 vt100_goto(state, col, row);
96 vt100_cursor_visibility(state, visible);
97}
98
99static void serial_char_update(outdev_t *dev, sysarg_t col, sysarg_t row)
100{
101 vt100_state_t *state = (vt100_state_t *) dev->data;
102 charfield_t *field =
103 chargrid_charfield_at(dev->backbuf, col, row);
104
105 draw_char(state, field, col, row);
106}
107
108static outdev_ops_t serial_ops = {
109 .yield = serial_yield,
110 .claim = serial_claim,
111 .get_dimensions = serial_get_dimensions,
112 .get_caps = serial_get_caps,
113 .cursor_update = serial_cursor_update,
114 .char_update = serial_char_update
115};
116
117int serial_init(vt100_putchar_t putchar_fn,
118 vt100_control_puts_t control_puts_fn)
119{
120 vt100_state_t *state =
121 vt100_state_create(SERIAL_COLS, SERIAL_ROWS, putchar_fn,
122 control_puts_fn);
123 if (state == NULL)
124 return ENOMEM;
125
126 outdev_t *dev = outdev_register(&serial_ops, state);
127 if (dev == NULL) {
128 vt100_state_destroy(state);
129 return ENOMEM;
130 }
131
132 return EOK;
133}
134
135/** @}
136 */
Note: See TracBrowser for help on using the repository browser.