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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8d2dd7f2 was 8d2dd7f2, checked in by Jakub Jermar <jakub@…>, 8 years ago

Reduce the number of files that include <sys/types.h>

  • Property mode set to 100644
File size: 3.7 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 <errno.h>
38#include <io/chargrid.h>
39#include "../output.h"
40#include "../proto/vt100.h"
41#include "serial.h"
42
43#define SERIAL_COLS 80
44#define SERIAL_ROWS 24
45
46/** Draw the character at the specified position.
47 *
48 * @param state VT100 protocol state.
49 * @param field Character field.
50 * @param col Horizontal screen position.
51 * @param row Vertical screen position.
52 *
53 */
54static void draw_char(vt100_state_t *state, charfield_t *field,
55 sysarg_t col, sysarg_t row)
56{
57 vt100_goto(state, col, row);
58 vt100_set_attr(state, field->attrs);
59 vt100_putchar(state, field->ch);
60}
61
62static int serial_yield(outdev_t *dev)
63{
64 vt100_state_t *state = (vt100_state_t *) dev->data;
65
66 return vt100_yield(state);
67}
68
69static int serial_claim(outdev_t *dev)
70{
71 vt100_state_t *state = (vt100_state_t *) dev->data;
72
73 return vt100_claim(state);
74}
75
76static void serial_get_dimensions(outdev_t *dev, sysarg_t *cols,
77 sysarg_t *rows)
78{
79 vt100_state_t *state = (vt100_state_t *) dev->data;
80
81 vt100_get_dimensions(state, cols, rows);
82}
83
84static console_caps_t serial_get_caps(outdev_t *dev)
85{
86 return (CONSOLE_CAP_STYLE | CONSOLE_CAP_INDEXED);
87}
88
89static void serial_cursor_update(outdev_t *dev, sysarg_t prev_col,
90 sysarg_t prev_row, sysarg_t col, sysarg_t row, bool visible)
91{
92 vt100_state_t *state = (vt100_state_t *) dev->data;
93
94 vt100_goto(state, col, row);
95 vt100_cursor_visibility(state, visible);
96}
97
98static void serial_char_update(outdev_t *dev, sysarg_t col, sysarg_t row)
99{
100 vt100_state_t *state = (vt100_state_t *) dev->data;
101 charfield_t *field =
102 chargrid_charfield_at(dev->backbuf, col, row);
103
104 draw_char(state, field, col, row);
105}
106
107static outdev_ops_t serial_ops = {
108 .yield = serial_yield,
109 .claim = serial_claim,
110 .get_dimensions = serial_get_dimensions,
111 .get_caps = serial_get_caps,
112 .cursor_update = serial_cursor_update,
113 .char_update = serial_char_update
114};
115
116int serial_init(vt100_putchar_t putchar_fn,
117 vt100_control_puts_t control_puts_fn)
118{
119 vt100_state_t *state =
120 vt100_state_create(SERIAL_COLS, SERIAL_ROWS, putchar_fn,
121 control_puts_fn);
122 if (state == NULL)
123 return ENOMEM;
124
125 outdev_t *dev = outdev_register(&serial_ops, state);
126 if (dev == NULL) {
127 vt100_state_destroy(state);
128 return ENOMEM;
129 }
130
131 return EOK;
132}
133
134/** @}
135 */
Note: See TracBrowser for help on using the repository browser.