Changeset 7eaeec1 in mainline for uspace/srv/hid/output/ctl/serial.c
- Timestamp:
- 2012-08-20T21:27:38Z (12 years ago)
- 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. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/output/ctl/serial.c
rf3a37e28 r7eaeec1 28 28 */ 29 29 30 /** @file 30 /** @addtogroup console 31 * @{ 32 */ 33 /** 34 * @file 31 35 */ 32 36 33 37 #include <sys/types.h> 34 38 #include <errno.h> 35 #include < malloc.h>36 #include <screenbuffer.h>39 #include <io/chargrid.h> 40 #include "../output.h" 37 41 #include "../proto/vt100.h" 38 #include "../fb.h"39 42 #include "serial.h" 40 43 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. 42 48 * 43 49 * @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. 47 53 * 48 54 */ 49 static void draw_ vp_char(vt100_state_t *state, fbvp_t *vp, sysarg_t col,50 sysarg_t row)55 static void draw_char(vt100_state_t *state, charfield_t *field, 56 sysarg_t col, sysarg_t row) 51 57 { 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); 58 59 vt100_set_attr(state, field->attrs); 59 60 vt100_putchar(state, field->ch); 60 61 } 61 62 62 static int serial_yield( fbdev_t *dev)63 static int serial_yield(outdev_t *dev) 63 64 { 64 65 vt100_state_t *state = (vt100_state_t *) dev->data; 66 65 67 return vt100_yield(state); 66 68 } 67 69 68 static int serial_claim( fbdev_t *dev)70 static int serial_claim(outdev_t *dev) 69 71 { 70 72 vt100_state_t *state = (vt100_state_t *) dev->data; 73 71 74 return vt100_claim(state); 72 75 } 73 76 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) 77 static void serial_get_dimensions(outdev_t *dev, sysarg_t *cols, 78 sysarg_t *rows) 103 79 { 104 80 vt100_state_t *state = (vt100_state_t *) dev->data; 105 81 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); 117 83 } 118 84 119 static console_caps_t serial_ vp_get_caps(fbdev_t *dev, fbvp_t *vp)85 static console_caps_t serial_get_caps(outdev_t *dev) 120 86 { 121 87 return (CONSOLE_CAP_STYLE | CONSOLE_CAP_INDEXED); 122 88 } 123 89 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) 90 static void serial_cursor_update(outdev_t *dev, sysarg_t prev_col, 91 sysarg_t prev_row, sysarg_t col, sysarg_t row, bool visible) 127 92 { 128 93 vt100_state_t *state = (vt100_state_t *) dev->data; 129 94 130 vt100_goto(state, vp->x + col, vp->y +row);95 vt100_goto(state, col, row); 131 96 vt100_cursor_visibility(state, visible); 132 97 } 133 98 134 static void serial_vp_char_update(fbdev_t *dev, fbvp_t *vp, sysarg_t col, 135 sysarg_t row) 99 static void serial_char_update(outdev_t *dev, sysarg_t col, sysarg_t row) 136 100 { 137 101 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); 139 106 } 140 107 141 static fbdev_ops_t serial_ops = {108 static outdev_ops_t serial_ops = { 142 109 .yield = serial_yield, 143 110 .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 152 115 }; 153 116 … … 156 119 { 157 120 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); 159 123 if (state == NULL) 160 124 return ENOMEM; 161 125 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 } 165 131 166 132 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.