Changeset 7eaeec1 in mainline for uspace/srv/hid/output/ctl/serial.c


Ignore:
Timestamp:
2012-08-20T21:27:38Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6a97f2e
Parents:
f3a37e28 (diff), dd13349 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 moved

Legend:

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

    rf3a37e28 r7eaeec1  
    2828 */
    2929
    30 /** @file
     30/** @addtogroup console
     31 * @{
     32 */
     33/**
     34 * @file
    3135 */
    3236
    3337#include <sys/types.h>
    3438#include <errno.h>
    35 #include <malloc.h>
    36 #include <screenbuffer.h>
     39#include <io/chargrid.h>
     40#include "../output.h"
    3741#include "../proto/vt100.h"
    38 #include "../fb.h"
    3942#include "serial.h"
    4043
    41 /** Draw the character at the specified position in viewport.
     44#define SERIAL_COLS  80
     45#define SERIAL_ROWS  24
     46
     47/** Draw the character at the specified position.
    4248 *
    4349 * @param state VT100 protocol state.
    44  * @param vp    Viewport.
    45  * @param col   Screen position relative to viewport.
    46  * @param row   Screen position relative to viewport.
     50 * @param field Character field.
     51 * @param col   Horizontal screen position.
     52 * @param row   Vertical screen position.
    4753 *
    4854 */
    49 static void draw_vp_char(vt100_state_t *state, fbvp_t *vp, sysarg_t col,
    50     sysarg_t row)
     55static void draw_char(vt100_state_t *state, charfield_t *field,
     56    sysarg_t col, sysarg_t row)
    5157{
    52         sysarg_t x = vp->x + col;
    53         sysarg_t y = vp->y + row;
    54        
    55         charfield_t *field = screenbuffer_field_at(vp->backbuf, col, row);
    56        
    57         vt100_goto(state, x, y);
     58        vt100_goto(state, col, row);
    5859        vt100_set_attr(state, field->attrs);
    5960        vt100_putchar(state, field->ch);
    6061}
    6162
    62 static int serial_yield(fbdev_t *dev)
     63static int serial_yield(outdev_t *dev)
    6364{
    6465        vt100_state_t *state = (vt100_state_t *) dev->data;
     66       
    6567        return vt100_yield(state);
    6668}
    6769
    68 static int serial_claim(fbdev_t *dev)
     70static int serial_claim(outdev_t *dev)
    6971{
    7072        vt100_state_t *state = (vt100_state_t *) dev->data;
     73       
    7174        return vt100_claim(state);
    7275}
    7376
    74 static int serial_get_resolution(fbdev_t *dev, sysarg_t *width, sysarg_t *height)
    75 {
    76         vt100_state_t *state = (vt100_state_t *) dev->data;
    77         vt100_get_resolution(state, width, height);
    78         return EOK;
    79 }
    80 
    81 static void serial_font_metrics(fbdev_t *dev, sysarg_t width, sysarg_t height,
    82     sysarg_t *cols, sysarg_t *rows)
    83 {
    84         *cols = width;
    85         *rows = height;
    86 }
    87 
    88 static int serial_vp_create(fbdev_t *dev, fbvp_t *vp)
    89 {
    90         vp->attrs.type = CHAR_ATTR_STYLE;
    91         vp->attrs.val.style = STYLE_NORMAL;
    92         vp->data = NULL;
    93        
    94         return EOK;
    95 }
    96 
    97 static void serial_vp_destroy(fbdev_t *dev, fbvp_t *vp)
    98 {
    99         /* No-op */
    100 }
    101 
    102 static void serial_vp_clear(fbdev_t *dev, fbvp_t *vp)
     77static void serial_get_dimensions(outdev_t *dev, sysarg_t *cols,
     78    sysarg_t *rows)
    10379{
    10480        vt100_state_t *state = (vt100_state_t *) dev->data;
    10581       
    106         for (sysarg_t row = 0; row < vp->rows; row++) {
    107                 for (sysarg_t col = 0; col < vp->cols; col++) {
    108                         charfield_t *field =
    109                             screenbuffer_field_at(vp->backbuf, col, row);
    110                        
    111                         field->ch = 0;
    112                         field->attrs = vp->attrs;
    113                        
    114                         draw_vp_char(state, vp, col, row);
    115                 }
    116         }
     82        vt100_get_dimensions(state, cols, rows);
    11783}
    11884
    119 static console_caps_t serial_vp_get_caps(fbdev_t *dev, fbvp_t *vp)
     85static console_caps_t serial_get_caps(outdev_t *dev)
    12086{
    12187        return (CONSOLE_CAP_STYLE | CONSOLE_CAP_INDEXED);
    12288}
    12389
    124 static void serial_vp_cursor_update(fbdev_t *dev, fbvp_t *vp,
    125     sysarg_t prev_col, sysarg_t prev_row, sysarg_t col, sysarg_t row,
    126     bool visible)
     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)
    12792{
    12893        vt100_state_t *state = (vt100_state_t *) dev->data;
    12994       
    130         vt100_goto(state, vp->x + col, vp->y + row);
     95        vt100_goto(state, col, row);
    13196        vt100_cursor_visibility(state, visible);
    13297}
    13398
    134 static void serial_vp_char_update(fbdev_t *dev, fbvp_t *vp, sysarg_t col,
    135     sysarg_t row)
     99static void serial_char_update(outdev_t *dev, sysarg_t col, sysarg_t row)
    136100{
    137101        vt100_state_t *state = (vt100_state_t *) dev->data;
    138         draw_vp_char(state, vp, col, row);
     102        charfield_t *field =
     103            chargrid_charfield_at(dev->backbuf, col, row);
     104       
     105        draw_char(state, field, col, row);
    139106}
    140107
    141 static fbdev_ops_t serial_ops = {
     108static outdev_ops_t serial_ops = {
    142109        .yield = serial_yield,
    143110        .claim = serial_claim,
    144         .get_resolution = serial_get_resolution,
    145         .font_metrics = serial_font_metrics,
    146         .vp_create = serial_vp_create,
    147         .vp_destroy = serial_vp_destroy,
    148         .vp_clear = serial_vp_clear,
    149         .vp_get_caps = serial_vp_get_caps,
    150         .vp_cursor_update = serial_vp_cursor_update,
    151         .vp_char_update = serial_vp_char_update
     111        .get_dimensions = serial_get_dimensions,
     112        .get_caps = serial_get_caps,
     113        .cursor_update = serial_cursor_update,
     114        .char_update = serial_char_update
    152115};
    153116
     
    156119{
    157120        vt100_state_t *state =
    158             vt100_state_create(80, 24, putchar_fn, control_puts_fn);
     121            vt100_state_create(SERIAL_COLS, SERIAL_ROWS, putchar_fn,
     122            control_puts_fn);
    159123        if (state == NULL)
    160124                return ENOMEM;
    161125       
    162         fbdev_t *dev = fbdev_register(&serial_ops, state);
    163         if (dev == NULL)
    164                 return EINVAL;
     126        outdev_t *dev = outdev_register(&serial_ops, state);
     127        if (dev == NULL) {
     128                vt100_state_destroy(state);
     129                return ENOMEM;
     130        }
    165131       
    166132        return EOK;
Note: See TracChangeset for help on using the changeset viewer.